0

我正在尝试调用一个返回 xml 数据的球衣 Web 服务。该调用是通过具有以下格式的 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);
        }
    });

当我在导航器中键入 url 时,我会在浏览器中获得以下格式的 xml:

<categoryBeans>
<categoryBean>
<code>1</code>
<name>Nutella</name>
</categoryBean>
<categoryBean>
<code>2</code>
<name>Kinder</name>
</categoryBean>
</categoryBeans>

但是当我从 html5 应用程序进行 Ajax 调用时,没有返回任何内容。

如何调试 ajax 调用?ajax 调用是否正确?

干杯

4

1 回答 1

2

您在成功处理程序的结尾和失败处理程序的开始之间缺少逗号。应该:

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. See http://en.wikipedia.org/wiki/Same_origin_policy

Firebug or Chome's Dev Tools are very useful for debugging issues like this.

于 2012-09-16T22:34:50.363 回答