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>

JQUERY

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 に答える