1

整数/浮点数一切正常,但当我在文本框中输入字符串时,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;
        }
4

1 回答 1

3
data: "{\"userData\":" + userData + "}"

应该:

data: "{\"userData\":'" + userData + "'}"
于 2012-09-25T21:40:18.417 回答