-1

I have an application where I am required to perform multiple form submits to external sites. I want the form submits to open new tabs. What I do is I create a form element using javascript, and then I just do a form.submit(). I am aware that only one will make it through.

I am looking for work arounds. One way is using jsonp:

I have something like this so far

$.ajax({
    dataType: 'jsonp',
    url: path, 
    type: "POST", 
    async: "false",
    contentType: 'application/x-javascript',
    data: $('this').serializeArray(),
    success: function (html) {
        if (data != "") {     
                var link = html;
                window.open(link,'', ''); //open's link in newly opened tab!
            }
      },
      failure: function (html) {
        alert(html);
      }
    });
        return false; 
    });

However even I do specified the type to be post, I see in the chrome developer tools that I have an actual get being sent. I am guessing that is because of window.open.

Can somebody suggest techniques to achieve this/

Thank you

oneiros
  • 3,527
  • 12
  • 44
  • 71
  • 1
    *"However even I do specified the type to be post, I see in the chrome developer tools that I have an actual get being sent. I am guessing that is because of window.open."* No, it's because [JSONP](http://en.wikipedia.org/wiki/JSONP#JSONP) is **inherently** a `GET` operation. – T.J. Crowder May 10 '13 at 21:24
  • For additional explanation, see http://stackoverflow.com/questions/4508198/how-to-use-type-post-in-jsonp-ajax-call – George Cummins May 10 '13 at 21:25
  • Whoever marked this as a duplicate and guided me to a "How to use type: “POST” in jsonp ajax call" - please be aware that my question is not how to use POST with jsonp ajax calls. My question is to perform Multiple Form Submits to Cross Domain Sites ... If there is a question that has this answered (there is none), then you can mark this as complete. – oneiros May 10 '13 at 23:39
  • I am guessing the best approach would be to have a proxy written in php, which receives the post and then posts it forward. – oneiros May 11 '13 at 03:17

1 Answers1

1

I am required to perform multiple form submits to external sites. I want the form submits to open new tabs. What I do is I create a form element using javascript, and then I just do a form.submit().

If you set the target attribute of the form element to "_blank" in the HTML, and set the action property of the form element instance to each of the external URLs in a loop (e.g., set the URL, call submit; set the next URL, call submit), you should be able to submit the form multiple times. (You'll probably have to do this within the handling of a user-generated event, and even then I wouldn't be absolutely sure a browser wouldn't — and shouldn't — block multiple new tabs sprouting up.)

But I would strongly push back on the original requirement, unless it's absolutely clear to the end user what you're going to be doing when they click that button or whatever.

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875