0

I have a JQGrid and search filters and loadOnce=false. I search records in grid and i am able to see this json GET type in firebug.

http://localhost:8080/myapp/items/listGrid?ticketId=&_search=true&nd=1393573713370&rows=20&page=1&sidx=id&sord=asc&filters=%7B%22groupOp%22%3A%22AND%22%2C%22rules%22%3A%5B%7B%22field%22%3A%22summary%22%2C%22op%22%3A%22cn%22%2C%22data%22%3A%22Test%22%7D%5D%7D

I want to get this JSON request URL after this request completed I have to add same params to my pdf link.

I try

document.URL
window.location.pathname
jQuery("#itemsGrid").jqGrid('getGridParam', 'url');

output

"localhost:8080/myapp/items/list"
"/myapp/items/list"
"/myapp/items/listGrid?ticketId="

How can I get the same URL?

halfer
  • 19,824
  • 17
  • 99
  • 186
Sun
  • 3,444
  • 7
  • 53
  • 83

2 Answers2

0

If it is an ajax call you could decorate the XMLHttpRequest.prototype.open function:

var calls = [];

XMLHttpRequest.prototype._originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
   if(method === 'GET') // Only add GET requests
       calls.push(url);
   this._originalOpen(method, url, async, user, password);
}

Now you can access the last get URL as follows

var lastUrl = calls[calls.length - 1]

Adopted this code from this SO question.

Community
  • 1
  • 1
Dieterg
  • 16,118
  • 3
  • 30
  • 49
  • it need to pass user credentials, i can not post in application directly or indirectly. Have any other solution please... – Sun Feb 28 '14 at 09:28
  • @kumarM: It sounds that you need **set** URL instead of **get** it. – Oleg Feb 28 '14 at 11:46
0

If you need to append the URL with additional parameters you should use postData parameter of jqGrid. I recommend to define parameters as functions (like in the answer). If you need to send user credentials information then you should better place it in custom HTTP headers instead of URL which can be seen by everybody. Usage of loadBeforeSend callback would be the best choice in the case. See the answer and this one for the code example. One more option which you have is the usage of beforeRequest callback to modify url parameter of jqGrid directly before the usage (see the answer)

The usage of https: instead of http: in the final solution would be recommend too.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798