【发布时间】:2017-01-19 22:32:25
【问题描述】:
我需要为内部通信创建一个简单的 HTTP GET 请求。
请求打开了一扇门。如果我在浏览器中输入此网址: http://172.27.1.20/api/switch/ctrl?switch=1&action=on 端口打开,浏览器显示它。
{
"success" : true
}
我尝试使用 Ajax 脚本发送 HTTP GET 但控制台日志显示:
ctrl?callback=jQuery1600571…_1473684252251&switch=1&action=on&_=1473685494405:2 Utncaught SyntaxError: Unexpected oken :
function test() {
$.ajax({
url: 'http://172.27.1.20/api/switch/ctrl',
type: 'GET',
data: {switch: 1, action: 'on'},
crossDomain: true,
dataType: 'jsonp',
dataCharset: 'jsonp',
contentType: 'application/json',
success: function (result) {
console.log("OK - RESULT: " + result);
},
error: function (result, error) {
console.log("ERROR - RESULT: " + result + " - TYPE ERROR: " + error);
}
});
}
有人可以帮我吗?
【问题讨论】:
-
我使用 jsonp 因为我需要从另一个域使用它。
-
如果对您有帮助,您可以接受下面的答案吗?