使用jquery ajax post在aspx中抛出“500 Internal Server Error”

时间:2015-01-27 10:17:09

标签: javascript c# jquery asp.net ajax

使用jquery ajax我正在调用一种方法" Dispatch_Job"并将参数传递给它进行插入但在这里抛出错误。

Establishment_Controller.aspx代码:

    function SendData(distance) {
                    $.ajax({
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        url: "Establishment_Controller.aspx/Dispatch_job",
                        dataType: "json",
                        data: "{'tbName': '" + $("#<%=TextBoxName.ClientID%>").val() +
                             "','tbFatherName': '" + $("#<%=TextBoxFatherName.ClientID%>").val() +
                             "','tbAddress':'" + $("#<%=TextBoxAddress.ClientID%>").val() +
                             "','tbPhNo':'" + $("#<%=TextBoxPhNumber.ClientID%>").val() +                         
                             "','tbDistance':'" + distance + "'}",
                        async: true,
                        success: function (data) {
                            alert('1 ' + data.d);
                        },
                        error: function (result) {
                            alert("Error! " + result.status + ', ' + result.statusText);
                        }
                    });
                }


<asp:TextBox ID="TextBoxName" CssClass="time" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBoxPicFatherName" CssClass="time" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBoxAddress" CssClass="time" runat="server"></asp:TextBox>
<asp:TextBox ID="TextBoxPhNo" onblur="SendData(0);" CssClass="time" runat="server"></asp:TextBox>

.cs代码:

[WebMethod]
public static string Dispatch_job(string tbName, string tbFatherName, string tbAddress, string tbPhNo, string tbdistance)
    {

         using (Estb_cntxtDataContext context = new Estb_cntxtDataContext())
                {
                Info j = new Info();

                j.name = tbName;
                j.fathername = tbFatherName;
                j.address = tbAddress;
                j.phoneNo = tbPhNo;
                j.distance = tbDistance;

                context.Info.InsertOnSubmit(j);
                context.SubmitChanges();

                return "Saved";
            }

    }

执行代码并填写所有文本框,并且在textboxPhNo上调用onblur属性时,它显示&#34; 500内部服务器错误&#34;。

0 个答案:

没有答案