简体   繁体   English

通过JQuery Ajax调用消耗xml web服务运动衫

[英]Consume a xml web-service jersey through a JQuery Ajax call

I'm trying to call a jersey Webservice which returns xml data. 我正在尝试调用返回xml数据的球衣Webservice。 The call is done with a jquery ajax call which has the following format: 调用是通过jquery ajax调用完成的,该调用具有以下格式:

$.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: 当我在导航器中键入url时,我在浏览器中使用以下格式获取xml:

<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. 但是当我从html5应用程序进行Ajax调用时,不会返回任何内容。

How can I debug the ajax call?Is the ajax call correct? 如何调试ajax调用?ajax调用是否正确?

Cheers 干杯

You're missing a comma between the end of your success handler and the start of your failure handler. 您在成功处理程序结束和失败处理程序启动之间缺少逗号。 Should be: 应该:

success: function(resp){  
  alert("Hello"); 
},            
failure: function(errMsg) {
  alert(errMsg);
}

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. 如果您的HTTP服务器在80上运行且您的Jersey服务器在8080上运行,那么您将遇到相同的原始策略违规。 See http://en.wikipedia.org/wiki/Same_origin_policy 请参见http://en.wikipedia.org/wiki/Same_origin_policy

Firebug or Chome's Dev Tools are very useful for debugging issues like this. Firebug或Chome的Dev Tools对于调试此类问题非常有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM