i want invoke rest service in domain using jquery ajax request.
my piece of code : ad1,city,sp,pc,cn taken getelementbyid.
url='http://admin:admin@*******:***/rest/arun_code/results.json'+'?data.addressline1='+ad1+'&data.city='+city+'&data.stateprovince='+sp+'&data.postalcode='+pc+'&data.country='+cn; $.ajax({ type: "get", url: url, crossdomain: true, async: false, datatype: "jsonp", contenttype: "application/json", jsonpcallback: 'jsoncallback', success: function (data) { alert(data.success); alert(resulttemp.output); } }); jsoncallback = function(resulttemp){ alert("in callback function"); alert(resulttemp); };
in web browser console getting exception :
uncaught syntaxerror: unexpected token : @ results.json :1
with chrome developer tools can read response, fine :
{"output":[{"latitude":"43.643286156655485","longitude":"-79.37559537260091"}]}
i not getting alerts response, want output alert , accessible..
my server output json , have use jsonp cross domain request, how access on output???? please me.
thank you
your problem response not jsonp. wikipedia has explanation how jsonp works: http://en.wikipedia.org/wiki/jsonp
i.e.
{ "name": "foo", "id": 1234, "rank": 7 }
becomes
jsoncallback({"name": "foo", "id": 1234, "rank": 7});
you can't normal ajax request @ existing server , expect respond accordingly. need configure server respond appropriate jsonp format.
Comments
Post a Comment