2012-08-02 86 views
0

我使用html和jQuery代码开发了一个简单的网页,它将使用http post将数据传递到我的网关。来自服务器的响应是json对象,{“remarks”:“成功”}。然而,我的网页始终未能得到相关回应JSON POST未能获得响应数据

下面是我的网页代码

<!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> 

谁能帮助/建议我对此有何看法?

+0

你的脚本是否在'http:// localhost:8091 /'上运行? – 2012-08-02 14:57:32

+0

您是否尝试过使用Firefox/Firebug查看HTTP响应? – Steve 2012-08-02 15:11:40

回答

0

打开您的Firebug或Chrome开发者工具,并查看控制台。如果出现错误消息Origin is not allowed by Access-Control-Allow-Origin,则表示您违反了same origin policy

你可以解决这个问题:

  • 移动你的网页和JSON源相同的域下。

  • 改为使用JSONP