AJAX的REST API调用 - 卷曲作品,而阿贾克斯失败卷曲、作品、REST、AJAX

2023-09-11 01:13:05 作者:夜幕星河

我使用的是卷曲的API调用,我已经将它转换为阿贾克斯,但它不工作。任何想法?

I'm using a cURL api call and I've converted it to ajax but it doesn't work. Any ideas?

curl -v -X POST -H "Content-Type: application/json" -H "Accept: application/json" --user user:pass https://i.am.web/123456789/events -d "{\"name\": \"Marcus0.1\",\"start\": 500000,\"end\": 1361640526000}"

$.ajax({
    type: 'POST',
    url: 'https://i.am.web/123456789/events',
    dataType: 'application/json',
    accept: 'application/json',
    async: false,
    username: 'user',
    password: 'pass',
    data: {
        "name": "Marcus0.3",
        "start": 500000,
        "end": 1361640526000
    },
    success: function(){alert('DONE!');},
    error:function(error){alert(error)},
});
alert("ENDING API MAIN FUNCTION")

Chrome浏览器错误:

Chrome errors:

http://i.am.website/123456789 和放大器; POST和放大器; 401未授权和放大器; text / html的&放大器; query.min / JS:2脚本

http://i.am.website/123456789 & POST & 401 unauthorized & text/html & query.min/js:2 Script

推荐答案

跨域Ajax调用是不允许的。解决方案改变数据类型设置为JSONP,并使用GET方法,但在你的情况下,它可能是不可能的。

cross-domain ajax calls are not permitted. Solution change dataType to jsonp and use GET method, but in your case it's probably impossible.