2013-07-26 16 views
1

我有一個函數可以在javascript中創建表單並提交它。 它在Safari,Chrome,FF,& Opera中運行正常,但不是IE 10.Javascript窗體未按預期在IE上提交

當從瀏覽器提交的瀏覽器未指向IE中action屬性中的url時。我確定這是跛腳,但我找不到問題,所以任何幫助將不勝感激。

function checkout() { 
    var myDoc = 'some xml data to send' 
    var form = document.createElement("form"); 
    form.setAttribute("method", "POST"); 
    form.setAttribute("action", "http://domain.com/script.php"); 
    var hiddenField = document.createElement("input"); 
    hiddenField.setAttribute("type", "hidden"); 
    hiddenField.setAttribute("name", "myField"); 
    hiddenField.setAttribute("value", myDoc); 
    form.appendChild(hiddenField); 
    form.submit(); 
} 

感謝您的幫助!

回答

1

您正在創建表單,但未將其附加到文檔。

添加

document.documentElement.appendChild(form); 

只是

之前
form.submit(); 
+0

太感謝了,它總是明顯逃避我。 – SurferJoe