0

これが機能しない理由がわかりません (SendValues メソッドを呼び出せません)。エラーは発生しません。誰でも私を助けることができますか?どうもありがとうございました!

以下のようなhtmlページ:

 <script language="javascript" type="text/javascript">
     $(function () {
         $("#Button1").click(function () {
             $.ajax({
                 type: "POST",
                 url: "WebForm1.aspx/SendValues",
                 data: { 'Code': '1026' },
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",
                 success: function (json) {
                     alert(json.d);
                 },
                 failure: function () {
                     alert("Sorry,there is a error!");
                 }
             });

         });
     });
 </script>

C# コードのようなもの:

 public partial class WebForm1 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    [WebMethod]
    public static string SendValues(string Code)
    {
        string contects = string.Empty;

        return contects;
    }

}
4

2 に答える 2

0

この問題は、data: { 'Code': '1026' } を "data: { 'Code': '1026' }" に変更することで解決しました。

于 2012-08-20T15:54:48.933 に答える
0

データは次のように指定する必要があります。

data: '{ Code:["1026"]}'
于 2013-02-06T13:25:34.440 に答える