我有卷曲到服务器以获取信息的命令
curl -v -H "Content-Type:application/json" -H "X-KGP-AUTH-TOKEN: a5a95c30274611e2ae10000c29bb7331" -H "X-KGP-APPID:id.kenhgiaiphap.kcloud" -H "X-KGP-APPVER:0.0.1" -H "X-KGP-DEVID:xxx" -H "X-KGP-DEVTYPE:xxx" http://test.kenhgiaiphap.vn/kprice/account/profile/get/token
我写ajax来处理这个
$.ajax({
url: "http://test.kenhgiaiphap.vn/kprice/account/profile/get/token",
type: "POST",
cache: false,
dataType: 'json',
success: function() { alert('hello!'); },
error: function(html) { alert(html); },
beforeSend: setHeader
});
function setHeader(xhr) {
xhr.setRequestHeader('X-KGP-AUTH-TOKEN','a5a95c30274611e2ae10000c29bb7331');
xhr.setRequestHeader('X-KGP-APPVER', '0.0.1');
xhr.setRequestHeader('X-KGP-DEVID', 'xxx');
xhr.setRequestHeader('X-KGP-APPID','id.kenhgiaiphap.kcloud');
xhr.setRequestHeader('X-KGP-DEVTYPE', 'xxx');
}
但我有问题是
2XMLHttpRequest cannot load http://test.kenhgiaiphap.vn/kprice/account/profile/get/token. Origin http://localhost is not allowed by Access-Control-Allow-Origin.
并应要求是
token
test.kenhgiaiphap.vn/kprice/帐户/个人资料/获取
选项
(取消)
加载已取消
文字/纯文字
的jquery-1.7.2.min.js:2320
脚本
156B
0B
1.15秒
39毫秒
39毫秒1.11秒
感谢支持!
最佳答案
这是浏览器问题。
将dataType
更改为jsonp
或将callback=?
添加到您的网址中:
http://test.kenhgiaiphap.vn/kprice/account/profile/get/token?callback=?
将来参考https://stackoverflow.com/a/6396653/744255
关于javascript - 如何从curl命令转换为ajax请求,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13243595/