簡體   English   中英

IIS Request.Form和JavaScript XMLHTTPRequest在Firefox和Chrome中不起作用

[英]IIS Request.Form and JavaScript XMLHTTPRequest not working in Firefox and Chrome

我正在使用XMLHttpRequest將FormData發送到IIS服務器。 在服務器上,當瀏覽器為IE時,Request.Form對象具有表單數據,但是當瀏覽器為FireFox或Chrome時,它沒有表單數據。 下面的示例使用FormData對象將表單提交到服務器。 對於IE,Request.Form.Count為1。對於FireFox和Chrome,它為零。 在所有情況下,我都希望結果為1。我期望自己做錯了什么,但我沒有看到。

這是客戶端代碼:

<script>

    function SubmitForm() {
        var http = new XMLHttpRequest()
        var data = new FormData()
        data.append("Text1", document.getElementById("Text1").textContent);
        http.open("POST", "ajaxtest.aspx", true);
        http.setRequestHeader("Content-Type", "multipart/form-data");
        http.onreadystatechange = function () {
            if (http.readyState == 4 && http.status == 200) {
                alert(http.responseText);
            }
        }
        http.send(data);
    }
</script>
<body>
    <input id="Text1" type="text" value="This is text to the server" />
    <input id="Button1" type="button" value="button" onclick="SubmitForm()" />
</body>

這是服務器代碼:

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
    If Request.HttpMethod = "POST" Then
        Response.Write("Request.Form.Count=" & Request.Form.Count)
        Response.End()
    End If
End Sub

任何建議或解釋和解決方案將不勝感激。

原來問題是setRequestHeader。 我將其刪除並獲得了所需的行為。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM