我正在为自己写一篇报价系统。使用JS(失败)和CURL(工作)在Asana中创建任务
我有报价此网页,至极的作用: 一)与所报项目 B)创建一个谷歌的电子表格(做内记录) C)创建任务发送电子邮件给客户(已完成)在体式(失败)
在过去的2天,我一直在冲浪和阅读所有我能找到的,但解决方案从我脑海中跳过,所以我问你4 asistnace。
这是卷曲代码,至极工作得很好:现在
curl -H "Authorization: Bearer 0/7alotofnumbers" \
https://app.asana.com/api/1.0/tasks \
-d "projects=83694179XXXXXX" \
-d "tags[0]=269280227XXXXXX" \
-d "[email protected]" \
-d "due_on=2017-02-09" \
-d "name=testing with curl" \
-d "notes=it works just as expected" \
-d "followers[0][email protected]"
,我翻译的作品到asanataskcreate.coffee curl命令:
$.ajax
url: 'https://app.asana.com/api/1.0/tasks'
beforeSend: (xhr) ->
xhr.setRequestHeader 'Authorization', 'Bearer 0/7alotofnumbers'
return
contentType: 'application/json'
method: 'get'
data:
projects: [ 83694179XXXXXX ]
tags: [ 269280227XXXXXX ]
assignee: '[email protected]'
due_on: '2017-02-09'
name: 'testing with js ajax'
notes: 'it does not work'
followers: [ '[email protected]' ]
至极变成asanataskcreate.js:
$.ajax({
url: 'https://app.asana.com/api/1.0/tasks',
beforeSend: function(xhr) {
xhr.setRequestHeader('Authorization', 'Bearer 0/7alotofnumbers');
},
contentType: 'application/json',
method: 'get',
data: {
projects: [83694179XXXXXX],
tags: [269280227XXXXXX],
assignee: '[email protected]',
due_on: '2017-02-28',
name: 'testing with js ajax',
notes: 'it does not work',
followers: ['[email protected]']
}
});
而且,失败 :(
好吧,我曾尝试:
一)方法: '后' 和 '得到'
B)的地方,去掉 '[]'在proyects,标签和追随者
有了Chrome devtools在“控制台”我收到以下消息的帮助:
Failed to load resource: the server responded with a status of 400 (Bad Request)
和
XMLHttpRequest cannot load https://app.asana.com/api/1.0/tasks?projects%5B%5D=836941797XXXXXX&tags%5B%5…¬es=it+does+not+work&followers%5B%5D=myself%40atmysite.com.mx. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://atmysite.com.mx' is therefore not allowed access. The response had HTTP status code 400.
现在,在DevTools,检查从体位法的XHR响应时,这就是我得到:
message: "You should specify one of workspace, project, tag, section"
为u可以从代码中看到,有一个项目ID定义,但在JS失败和卷曲作品。
在分析作品卷曲和阿贾克斯失败为什么“项目”,所不同的是:
curl: projects=83694179XXXXXX
js ajax: projects%5B%5D=836941797XXXXXX ==> projects[]=836941797XXXXXX
任何人有任何的想法是什么,我做错了。
在前进,感谢乌拉圭回合时间和援助
感谢杰夫,但它也将失败。同时我正在使用CURL方法。为了避免拾取眼睛,我混淆了php代码。 – OfficeYA