jQuery.ajax() 仅适用于整数



整数/浮点数一切都很好,但是当我在文本框中输入字符串时,C#方法GetData永远不会收到数据。

ASP 代码

<asp:TextBox id="txtBoxVersion" runat="server"></asp:TextBox>
    <asp:ImageButton id="iconVersionSave" class="iconSave" runat="server" imageUrl="Resources/iconSave.png" OnClientClick="asyncServerCall(document.getElementById('txtBoxVersion').value); return false;"></asp:ImageButton>

简讯

function asyncServerCall(userData) 
{
    jQuery.ajax(
    {
        url: 'SurveyUpload.aspx/GetData',
        type: "POST",
        data: "{"userData":" + userData + "}",           //Data to be sent to the server !!WARNING!! Field Name must match C# parameter name
        contentType: "application/json; charset=utf-8",  //when sending data to the server
        dataType: "json",                                //The type of data that you're expecting back from the server.
        success:
            function (data) 
            {
                alert('Success');}
            }
    });
}

C#

[WebMethod()]
        public static Boolean GetData(String userData)
        {
            System.Diagnostics.Debug.WriteLine(userData); //DEBUGGING
            return true;
        }
data: "{"userData":" + userData + "}"

应该是:

data: "{"userData":'" + userData + "'}"

最新更新