我在使用surveyMonkey API 时遇到问题。我可以使用除 Crate_flow 和 Send_flow 之外的任何公共方法。这两个在控制台中引发了我的错误:
选项 http://api.surveymonkey.net/v2/client/create_flow?api_key= **MYAPI* 596 (596) Index.html:61 XMLHttpRequest 无法加载http://api.surveymonkey.net/v2/client/create_flow ?api_key= **MYAPI*。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,Origin 'null' 不允许访问。Index.html:61 未捕获的网络错误:无法在“XMLHttpRequest”上执行“发送”:无法加载“ http://api.surveymonkey.net/v2/client/create_flow?api_key=**MYAPI* ”。
我正在使用的代码是这样的:
var xhr = new XMLHttpRequest();
xhr.open("POST", "http://api.surveymonkey.net/v2/batch/send_flow?api_key="+MYAPI, false);
xhr.setRequestHeader('Access-Control-Allow-Origin' ,'*');
xhr.setRequestHeader('Authorization','bearer '+TOKEN);
xhr.setRequestHeader('Content-Type', 'application/json');
var body = '{"survey_id" :"54681373","collector":{"type":"email", "recipients":[{"email": "martins.nuno.santos@gmail.com", "first_name": "Nuno", "last_name": "Santos"}],"send":true}, "email_message":{"reply_email":"martins.nuno.santos@gmail.com", "subject":"YOLO", "body_text": "Vamos lá experimentar isto ! [SurveyLink], para remover carrega em [RemoveLink]"}}';
xhr.send(body);
console.log(xhr.status);
console.log(xhr.statusText);
console.log(xhr.responseText);