0

Jquery UIダイアログのボタン呼び出しでjQuery Ajax「POST」リクエストを呼び出したいだけです。コードスニペットは次のとおりです。

    $("#addqust").dialog({
        autoOpen: false,
        width: 630,
        modal: true,
        resizable: false,
        position: { my: "top", at: "top", of: window },
        buttons: {
            "Save": function (e) {                        
                $.ajax({
                    type: "POST",
                    url: "Default.aspx/InsertQuestion",
                    contentType: "application/json; charset=utf-8",                                                        
                    data: { name: $("#qst").val() },
                    success: function (data) {
                        console.log($("#qst").val());
                        console.log(data.d);
                        // alert("message");
                    }
                    }).done(function (msg) {
                        alert("Data Saved ");
                });
            },
            "Cancel": function () {
                $(this).dialog("close");
            }
        }
    });

しかし、次のエラーまたは console.log が表示され、Page Web メソッドを呼び出していません。

POST http://localhost:50583/Default.aspx/InsertQuestion 500 (Internal Server Error) 
send 
v.extend.ajax 
$.dialog.buttons.Save 
(anonymous function) 
v.event.dispatch 
o.handle.u

私が犯したエラーを知りたいのですが、助けていただければ幸いです。

テスト用の簡単なメソッドである WebMethod を更新します。

[WebMethod()]
public static string InsertQuestion(string name)
{
    try
    {           
        string strjson;
        strjson = name;
        return strjson;
    }
    catch (Exception ex)
    {
        throw new System.Exception( ex.Message);
    }
}

使用されるjqueryのバージョン、

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js" type="text/javascript"></script>
    <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.1/jquery-ui.min.js" type="text/javascript"></script>
4

2 に答える 2

0

Fiddler をインストールして、トラフィックを確認します。投稿にエラーがあるか、少なくともサーバーが 500 を返しています。

http://fiddler2.com/

于 2013-07-09T17:27:16.480 に答える