0

我使用 html 和 jquery 代码开发了一个简单的网页,该网页将使用 http post 将数据传递到我的网关。来自服务器的响应是 json 对象,{"remarks":"SUCCEED"}。但是,我的网页总是无法得到相关响应

下面是我的网页代码

  <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Loading data into a PhoneGap ap2p</title>    
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
    <script src="jquery.jsonp.js"></script>
</head>
<body>
    <ul id="your-tweets"></ul>
</body>
<script>
$(document).ready(function(){

$.ajax({
    type: 'POST',
    url: 'http://localhost:8091/gateway/jjh/v1.0/login?userid=ccc&password=pwd',
    crossDomain: true,
    data: 'userid=wcc',
    dataType: 'json',
    success: function(responseData, textStatus, jqXHR) {
    alert("Success>>");

    var obj = responseData;
    alert(obj.remarks);

    },
    error: function (responseData, textStatus, errorThrown) {
        alert('POST failed.');
    }
}); 
});
</script>
</html>

任何人都可以帮助/建议我吗?

4

1 回答 1

0

打开您的 Firebug 或 Chrome 开发人员工具并查看控制台。如果出现错误消息,Origin is not allowed by Access-Control-Allow-Origin则说明您违反了同源策略

您可以通过以下方式解决此问题:

  • 将您的网页和 JSON 源移动到同一个域下。

  • 请改用JSONP

于 2012-08-02T15:13:41.560 回答