AJAX的REST API调用 - 卷曲作品,而阿贾克斯失败 [英] aJax REST API call - Curl Works while aJax fails

查看:121
本文介绍了AJAX的REST API调用 - 卷曲作品,而阿贾克斯失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是卷曲的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.

这篇关于AJAX的REST API调用 - 卷曲作品,而阿贾克斯失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆