jquery - Error when trying to get JSON data from a web service -
my customer provided me webservice link return json data. browsed , result. when created simple html page , using jquery ajax
var mycallback = function (data) { alert("data:" + data); }; var url = "http://xxx/gettoken"; var params = { username: "abc", password: "123" } $.ajax({ type: "get", url: url, data: params, contenttype: "text/plain", datatype: 'jsonp', crossdomain: true, cache: false, success: mycallback, error: function (xmlhttprequest, textstatus, errorthrown) { alert(errorthrown); alert(xmlhttprequest.responsetext); }, async: false });
it return error "networkerror" tracked result fiddle, result shown browser ???
and when change url example to:
var url = "http://api.openweathermap.org/data/2.5/weather"; var params = { lat: "35", lon: "139" }
it works well!....i don't know problem iis configuration or jquery ajax library.
do have solution solve problem?
thanks!!!
the problem you
a) use jsonp should use json,
jsonp technique of sending json-data
b) async set off, broswer expects response @ moment sends request,
while should waiting response.
so try this
var mycallback = function (data) { alert("data:" + data); }; var url = "http://xxx/gettoken"; var params = { username: "abc", password: "123" } $.ajax({ type: "get", url: url, data: params, contenttype: "text/plain", datatype: 'json', crossdomain: true, cache: false, success: mycallback, error: function (xmlhttprequest, textstatus, errorthrown) { alert(errorthrown); alert(xmlhttprequest.responsetext); }, async: true });
Comments
Post a Comment