1つのフォームをajaxなしで2つの異なる場所に送信するにはどうすればよいですか(クロスドメインの問題)
私は以下のようなことを考えていました。どのようにパラメータを渡すのでしょうか?
< 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>
ここから取得した関数>>フォーム送信のようなJavaScriptPOSTリクエスト
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();
}
ありがとうございました。