aJax REST API 调用 - 当 aJax 失败时 Curl 有效 [英] aJax REST API call - Curl Works while aJax fails

查看:24
本文介绍了aJax REST API 调用 - 当 aJax 失败时 Curl 有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 cURL api 调用并将其转换为 ajax,但它不起作用.有什么想法吗?

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 错误:

http://i.am.website/123456789 &邮政和401 未授权 &文本/html &query.min/js:2 脚本

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

推荐答案

不允许跨域 ajax 调用.解决方案将 dataType 更改为 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 调用 - 当 aJax 失败时 Curl 有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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