I’m trying to call a jersey Webservice which returns xml data. The call is done with a jquery ajax call which has the following format:
$.ajax({
type: "GET",
url: "http://localhost:8080/store/api/categoryservice",
contentType: "application/xml; charset=utf-8",
dataType: "xml",
success: function(resp){
alert("Hello");
}
failure: function(errMsg) {
alert(errMsg);
}
});
When I type the url in the navigator I get xml in the browser with the following format:
<categoryBeans>
<categoryBean>
<code>1</code>
<name>Nutella</name>
</categoryBean>
<categoryBean>
<code>2</code>
<name>Kinder</name>
</categoryBean>
</categoryBeans>
but when I make an Ajax call from html5 app, nothing is returned.
How can I debug the ajax call?Is the ajax call correct?
Cheers
You’re missing a comma between the end of your success handler and the start of your failure handler. Should be:
Also note that you’ll need to be running this page from the same server and port. If your HTTP server is running on 80 and your Jersey server is running on 8080 then you’ll run into same origin policy violations. See http://en.wikipedia.org/wiki/Same_origin_policy
Firebug or Chome’s Dev Tools are very useful for debugging issues like this.