使用 JSONP 从服务器返回响应
[重新编辑] 我正在尝试将一个值传递给服务器并使用 JSONP 从服务器读取。我已经能够实现这段代码:
var record = new Object();
record["deviceID"] = "123";
options = {
url: "http://192.168.2.143:8080/commapi/comaction/init?callback=?",
type: "POST",
data: {dataset: JSON.stringify(record) },
jsonp: "callback",
dataType: "jsonp",
callbackParameter: "jsoncallback",
success: function(result) {
alert(result["retdic.deviceID"]);
},
error: function(XHR, textStatus, errorThrown){
alert("ERROR: " + textStatus);
alert("ERROR: " + errorThrown);
}
};
jQuery.ajax(options);
});
但是我收到来自 FireFox firebug 的无效标签错误。谁能让我知道我做错了什么?几个例子就太好了;我们不胜感激。
谢谢。
[重新编辑] 产生的错误是:
invalid label
{"ret":"ACK","retdic":{"ak":"Bvr7/ljfj...X212yA+XJR5+AdrmE=","deviceID":"123"}}
返回的错误是parseError。我不确定我哪里出错了。有人可以帮我吗?
谢谢。
[RE-EDIT]
I am trying to pass a value to the server and read from the server using JSONP. I have been able to implement this code:
var record = new Object();
record["deviceID"] = "123";
options = {
url: "http://192.168.2.143:8080/commapi/comaction/init?callback=?",
type: "POST",
data: {dataset: JSON.stringify(record) },
jsonp: "callback",
dataType: "jsonp",
callbackParameter: "jsoncallback",
success: function(result) {
alert(result["retdic.deviceID"]);
},
error: function(XHR, textStatus, errorThrown){
alert("ERROR: " + textStatus);
alert("ERROR: " + errorThrown);
}
};
jQuery.ajax(options);
});
However I receive an invalid label error from FireFox firebug. Could anyone please let me know what it is I am doing wrong? A few examples would be great;y appreciated.
Thanks.
[RE-EDIT]
The error produced is:
invalid label
{"ret":"ACK","retdic":{"ak":"Bvr7/ljfj...X212yA+XJR5+AdrmE=","deviceID":"123"}}
The error returned is parseError. I am not sure where I am going wrong. Could anyone give me a hand, please?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这可以解决您的问题:
Jquery getJSON 到外部 PHP 页面
只需确保您共享一些服务器端代码,以便我们知道响应应该是什么样子
This could solve your problem:
Jquery getJSON to external PHP page
Just make sure your shared some server-side code, so that we know how the response should look like
试试这个
try this