When I retrieve data from my localhost as JSON everything is OK. When I try to get that JSON data from a remote machine everything is OK too. I can parse that JSON data comes from my localhost into objects( a datagrid plugin: jqgrid renders it). However when I try to use remote source it doesn’t. At firebug it says 200 OK but it shows an error icon and writes it red. I checked the differences between my localhost and remote connection headers and I found that there is not that header at remote connection:
X-Requested-With XMLHttpRequest
I think problem may be that. I wasn’t setting it and it was working well. It occurs at remote request.
Any ideas to solve it?
PS: I tried setting Ajax headers but didn’t work:
$.ajaxSetup({
headers: {"X-Requested-With":"XMLHttpRequest"}
});
$("#userTable").jqGrid({
url:'http://xx.xx.x.xxx:8080/aa/bb/cc/user',
colNames:['User Name','Password'],
colModel:[
{name:'userName',index:'userName', width:100},
{name:'password',index:'password', width:55}
],
jsonReader: ...
...
});
When I use that setup I can not even see the GET Request from Firebug.
PS: I use Spring 3 with REST and Tomcat as web server.
I think that you have the Cross-site scripting issue. The problem can be solved if the server set some additional options in the HTTP header of the response. So the solution is not in the modifying of the client code like you do currently, but in the server code.
I recommend you examine the HTTP options which will be set in the HTTP header by
tables.googlelabs.comused in the demo from the answer. You will see that the server response has the following additional HTTP options:and the JSON response will be placed inside of the call of the function defined by
jsonCallbackparameter. If you would usejsonCallback=?jqGrid will generate the name of the function (something likejQuery16407707202236448429_1319101394784). You can read more aboutX-XSS-Protectionoption here and aboutX-Content-Type-Options: nosniffoption here.How you can see in the demo, the data will be displayed in the jqGrid, so the Cross-site scripting can be implemented in the jqGrid.
Because we call the server
tables.googlelabs.com, which not support jqGrid paging and sorting parameters, I used in the demoThe usage of string instead of object as the
postDatavalue will overwrite any other jqGrid parameters which are typically posted. In you case it will be not needed to do this and probably you need just useurl: 'http://xx.xx.x.xxx:8080/aa/bb/cc/user?jsonCallback=?'.In any way you need implement support of JSONP on your server. It means just that the server should “understand”
jsonCallbackparameter. The implementation depends on your server side implementation. It could be justcrossDomainScriptAccessEnabled="true"binding setting for thewebHttpBindingin case of WCF service (see here an example of theweb.config). See this answer and this one (or this one) additionally for ASP.NET Web services and ASP.NET MVC.