0

Using jquery ajax i am calling a method "Dispatch_Job" and passing parameters to it which does insertion but in here it throws error.

Establishment_Controller.aspx code:

    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 code:

[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";
            }

    }

when the code is executed and all the textboxes are filled and when the onblur property is called on textboxPhNo it shows "500 Internal Server Error".

Haider Khattak
  • 567
  • 3
  • 8
  • 32
  • Can you tell as any details about the `500 Internal Server Error`? At some place you should find some details (server error log, event viewer, ...). – Christoph Fink Jan 27 '15 at 10:19
  • error: function (result) { alert("Error! " + result.status + ', ' + result.statusText); } the code in the method "Dispatch_Job" does not execute and it thrown error in this block. this is mentioned above in the code – Haider Khattak Jan 27 '15 at 10:21
  • 1
    have you tried debugging your c# and stepping through the code to see where the error is thrown? Have you noticed you have reset the name property of `j` multiple times rather than each property? Can you also show the code for the `Info` class – Pete Jan 27 '15 at 10:21
  • @Pete...yes i have debugged it but it does not even jumps to the .cs code. – Haider Khattak Jan 27 '15 at 10:23
  • change distance to tbDistance in cs – husnain_sys Jan 27 '15 at 10:24
  • @Pete...i typed it manually so forgot to change the value...now give it a look...i does not work... – Haider Khattak Jan 27 '15 at 10:25
  • Also is the url correct? `Establishment_Controller.aspx/Dispatch_job/` looks wrong – Pete Jan 27 '15 at 10:25
  • Perhaps you should create a [json handler](http://stackoverflow.com/questions/5756147/basic-simple-asp-net-jquery-json-example) to handle your post – Pete Jan 27 '15 at 10:32
  • @Pete...can you please give me an example – Haider Khattak Jan 27 '15 at 10:34

0 Answers0