2016-05-23 1 views
1

私はAmazons Mechanical Turk(Mturk)を使用しており、次のHITが表示されるように課題を完了として提出しようとしています。jquery.ajaxによるMturk externalQuestion POST:Access-Control-Allow-Originエラー

私はexternalQuestionを使用しています。私のサーバーには、作業者が入力したすべてのデータが保存されています。作業員が終わった後、彼らは、次のPOSTを送信する送信ボタンをクリックしてください:

$.ajax({ 
    url: self.props.userData.turkSubmitTo + '/mturk/externalSubmit', 
    data: {assignmentId:self.props.userData.assignmentId}, 
    type: 'POST', 
    success: function(resp) { console.log('good');}, 
    error: function(resp, err) { console.log('fail'); console.log(resp); console.log(err);} 
}); 

残念ながら、私は次のエラーを取得:その

XMLHttpRequest cannot load https://workersandbox.mturk.com/mturk/externalSubmit?assignmentId=3AMYWKA6YBMSYVY7OGYPJIPCGPK6OK. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://shrouded-plains-8041.herokuapp.com' is therefore not allowed access. 

注意を私がしようとするdataTypeと「JSONP」で投稿する場合この明らかなクロスドメインの問題を回避してから、送信は正常に動作しますが、externalQuestion iframeは次のHITまで更新されません。

私はなぜこのクロスドメインの「アクセス制御可能な原点」問題を取得するのかわかりません。助けてください?

+0

をそのエラーのウェブ検索を行ってください。

Hi Ben -

I believe the problem is that your code is attempting to get the user's browser to submit an AJAX request to Amazon. Since the page with this code is being generated by your own app on Heroku, the browser does not allow this by default (making AJAX calls from one domain to another).

The solution is to have the code do a form submit, not an AJAX submit. See documentation for JQuery's form submit here: https://api.jquery.com/submit/ .

Let me know if that works for you.

Thanks, Taneem

をここでは、今のコードを提出しています。 1日に何度もここに現れます。 jsonpを使用する場合は、ajaxではないスクリプト要求なので、 'POST'とjsonpは使用できません。短い答えは、可能であれば、APIでCORSを有効にするか、プロキシを使用する必要があります – charlietfl

+0

ありがとうございました!はい、私はグーグルの運賃額をしました。 jsonpについては理にかなっており、なぜ期待通りに動作しないのでしょうか。 CORを有効にするためにapiにアクセスすることはできません。私はそれがプロキシでなければならないと思う。 AmazonのMturkは、この標準的な操作を行うために代理人を必要とするのは奇妙に思えます。 Mturkの経験があれば誰でもコメントしていただけますか? – Yetti

答えて

1

私はアマゾンで役立つ民族と接触して持って、彼らは答えた:

<rb.Modal.Footer> 
    <form name="mturk_form" method="post" id="mturk_form" action={self.props.userData.submitTo + "/mturk/externalSubmit"}> 
     <input type="hidden" value='' name="assignmentId" id={self.props.userData.assignmentId}/> 
     <rb.Input type="submit" style={{width:'70%', float: "left"}}/> 
     <rb.Button onClick={self.props.closeSubmit}>Cancel</rb.Button> 
    </form> 
関連する問題