aJax REST API调用 – 当aJax失败时,Curl工作

我正在使用cURL api调用,我已将其转换为ajax但它不起作用。 有任何想法吗?

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&POST&401 unauthorized&text / html&query.min / js:2 Script

不允许跨域ajax调用。 解决方案将dataType更改为jsonp并使用GET方法,但在您的情况下,它可能是不可能的。