how would I submit one form to two different location without ajax (cross-domain issue)
I was thinking of something like below. Only how would I pass params ?
< form action="urlOne.com/something" method="post" onsubmit="postToUrl("urlTwo.com/something");">
<input type="text" value="hello" name="hi"/>
<input type="submit" value="submit">
</form>
function taken from here >> JavaScript post request like a form submit
function postToUrl(url, params)
{
var form = $('<form>');
form.attr('action', url);
form.attr('method', 'POST');
var addParam = function(paramName, paramValue){
var input = $('<input type="hidden">');
input.attr({ 'id': paramName,
'name': paramName,
'value': paramValue });
form.append(input);
};
// Params is an Array.
if(params instanceof Array){
for(var i=0; i<params.length; i++){
addParam(i, params[i]);
}
}
// Params is an Associative array or Object.
if(params instanceof Object){
for(var key in params){
addParam(key, params[key]);
}
}
// Submit the form, then remove it from the page
form.appendTo(document.body);
form.submit();
form.remove();
}
Thank you.
You can only post one form at a time in a window. If you try to post two forms, one post will stop the other.
The solution would be to post the two forms to different windows. You can set the target of the first form to post to an iframe in the page or to a new window:
This way the two posts would load in separate windows, and wouldn’t stop each other.