Wednesday, 15 August 2012

jquery - Submit a form to two servers -


I want to be able to submit the form to two servers here (if there is a better way of doing this, I I am all ears)

I have an embedded embedded on mechanical turkey iframe is a form.

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

I need to inform my local server so that I can do some work right now . I need to post the results, so that the next work can be displayed by Turkey.

If I do not do this, then my server will have to make a choice for the Turk to make the job, which is incompatible.

I have tried many plans but could not take them to work.

I have tried to use AJAX for posting locally, and submit a form, using the code looks like this:

  <% = Form_for (@task ,: url = & gt; "http://workersandbox.mturk.com/mturk/externalSubmit",: remote = & gt; correct ;: method = & gt; "post" ,: Authenticity_token = & gt; wrong). F | & Gt%; ....   

and in my unchanged JS file

  $ (form). Post ({url: "/ notify", opt, function () {Console.log ("notified")});   

This is the result of a JS error

  XMLHttpRequest can not load http://workersandbox.mturk.com/mturk/externalSubmit Genesis http: / /mytest.herokuapp.com is not allowed by access-control-permission-origin   

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

Any suggestions regarding the correct method of doing so will be appreciated.

It's easy to do with jQuery. Basically if you use the .serialize () method, you can post the data to as many places as you want.

Say you have one such form:

gt; pre & lt; & Lt; Input type = "text" id = "field1" name = "field1" value = "abc123" /> & Lt; Input type = "text" id = "field2" name = "field2" value = "def456" /> & Lt; Input type = "submit" value = "submit" /> & Lt; / Form & gt;

You may have the following jQuery code that executes POST

  $ (function () {$ ('form'). Submit (function () {Var data = $ (this). Serialize (); $ .post ("http://www.location1.com/someplace/", data, function () {}); $ .post ("http: //www.location2.com/anotherPlace/ ", data, function () {}); return;});});    

No comments:

Post a Comment