jQuery Ajax call runs in error but firebug shows 200 ok and returned json -
i've read lot of threads ajax problems, i've still got no clue, cause problem:
i'm trying call restful service (internal) via ajax large json-string.
edit: how resolved problem - know not quite solution, since can't change on webservice use:
<!doctype html> <html> <head> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script> <script> jquery(document).ready(function(){ jquery.support.cors = true; jquery.ajax({ url: "<internalpage>", datatype: 'json' }) .error(function(xhr, err, status) { console.log(xhr + err + status); }) .then(function(data) { alert("success me"); $.each(data.portalservices, function(index, value) { $("#someid").append('<li>' + value.name + '</li>'); }); }); }); </script> </head> <body> <ul id="someid"></ul> </body> </html>
edit: works in ie not in ff.
this alert says: ajax error type: requesting page: status: 0 - error error thrown:
but in firebug:
response-header content-type application/json date thu, 06 mar 2014 07:44:32 gmt server apache-coyote/1.1 transfer-encoding chunked anfrage-headerquelltext anzeigen accept application/json, text/javascript, */*; q=0.01 accept-encoding gzip, deflate accept-language de-de,de;q=0.8,en-us;q=0.5,en;q=0.3 cache-control no-cache connection keep-alive host xxxxxx origin null pragma no-cache user-agent mozilla/5.0 (windows nt 6.1; wow64; rv:27.0) gecko/20100101 firefox/27.0 responce-header cache content-type application/json date thu, 06 mar 2014 07:44:32 gmt server apache-coyote/1.1 transfer-encoding chunked
status 200 ok response valid json (really, i've validated online) {"portalservices":[{"articleid":"abr_1043024010","name":"sk04 managed server: citrix basisservice","portalname":"zentrale arbeitsplatz-umgebung (citrix-basis)","preis":18.0000,"beschreibung":"mit diesem produkt stellen wir ihnen eine zentrale arbeitsplatz-umgebung (auf der basis von citrix) bereit, die folgende komponenten ....
but there no json tab.
when use cache false firebug does't show me response , error shown in alert following:
ajax error type:get requesting page: <internalpage> status: 0 - exception ..."failure" nsresult: "0x80004005 (ns_error_failure)" location "js frame :: <link jquery> :: .send :: line 6 " data: no .....
i tried ajax call service ( "http://rest-service.guides.spring.io/greeting") succeeded. , there json tab in firebug, thats maybe because json returned site not list of objects json returned internal sites webservice.
any ideas? think there might problem webservice, nice if got clues cause may be. lot.
even following it's still not working =/
headers: {'access-control-allow-origin': '<internalpage>'}, datatype: 'jsonp', crossdomain: true
the internalpage not on same domain, not response request external network. call spring services did work without explicitly allowing crossdomain or setting header above.
i try suggested here parsererror after jquery.ajax request jsonp content type , come tell if has worked.
edit: webservices changed in future can use jsonp instead of forcing jquery allow crossdomain ajax-calls.
edit: webservice has been changed, works fine datatype jsonp. =)
thx help.
you sure request causing error? $(document).ajaxerror
global error handler (called on error), may have different ajax call that's causing it
you can change code to:
jquery.ajax({ url: "http://<internalpage", datatype: 'json' }) .error(function(xhr, err, status) { console.log(xhr + err + status); }) .then(function(data) { alert("success me"); });
try different browser i.e. chrome, may have extension that's causing problem
are using same url i.e. not making cross-domain requests? jquery call webservice returns "no transport" error
Comments
Post a Comment