Search code examples
jqueryruby-on-railssame-origin-policymechanicalturk

Submit a form to two servers


I want to be able to submit forms to two server. Here's why (if there is a better way of doing this, I'm all ears)

I have an iframe embedded on mechanical turk. The iframe has a form in it.

When a worker submits the form, I need to do two things:

I need to notify my local server so that I can take some actions right away. I need to post the results to mturk so that the next job is displayed by turk.

If I do not do this, my server needs to poll turk for job completion, which is inefficient.

I have tried multiple schemes, but could not get them to work.

I have tried to use ajax to do one post locally, and one form submit, using code that looks like this:

<%= form_for(@task, :url => "http://workersandbox.mturk.com/mturk/externalSubmit", 
:remote => true, :method => "post", :authenticity_token => false) do |f| %>

....

and in my unobstrusive js file

$(form).post({url: "/notify",opt, function() {console.log("notify done")});

This results in a js error

XMLHttpRequest cannot load http://workersandbox.mturk.com/mturk/externalSubmit. Origin http://mytest.herokuapp.com is not allowed by Access-Control-Allow-Origin. 

I have no control over the server, so I cannot fix this problem.

Any suggestions about the right way of doing this would be gratefully accepted.


Solution

  • I decided that I was thinking about it all wrong. I should not be trying to submit a form twice. Instead, I am submitting just to turk, and using their notification service using SQS (http://docs.aws.amazon.com/AWSMechTurk/latest/AWSMechanicalTurkRequester/Concepts_NotificationsArticle.html) to get notified of the changes on the server