jQuery ajax call doesn't seem to do anything at all

Posted by icemanind on Stack Overflow See other posts from Stack Overflow or by icemanind
Published on 2013-06-26T03:57:38Z Indexed on 2013/06/27 10:21 UTC
Read the original article Hit count: 392

Filed under:
|
|
|
|

I am having a problem with making an ajax call in jQuery. Having done this a million times, I know I am missing something really silly here. Here is my javascript code for making the ajax call:

   function editEmployee(id) {
       $('#<%= imgNewEmployeeWait.ClientID %>').hide();
       $('#divAddNewEmployeeDialog input[type=text]').val('');
       $('#divAddNewEmployeeDialog select option:first-child').attr("selected", "selected");
       $('#divAddNewEmployeeDialog').dialog('open');
       $('#createEditEmployeeId').text(id);
       var inputEmp = {};
       inputEmp.id = id;
       var jsonInputEmp = JSON.stringify(inputEmp);
       debugger;
       alert('Before Ajax Call!');
       $.ajax({
           type: "POST",
           url: "Configuration.aspx/GetEmployee",
           data: jsonInputEmp,
           contentType: "application/json; charset=utf-8",
           dataType: "json",
           success: function (msg) {
               alert('success');
           },
           error: function (msg) {
               alert('failure');
           }
       });
   }

Here is my CS code that is trying to be called:

    [WebMethod]
    public static string GetEmployee(int id)
    {
        var employee = new Employee(id);

        return Newtonsoft.Json.JsonConvert.SerializeObject(employee, Newtonsoft.Json.Formatting.Indented);
    }

When I try to run this, I do get the alert that says Before Ajax Call!. However, I never get an alert back that says success or an alert that says failure. I did go into my CS code and put a breakpoint on the GetEmployee method. The breakpoint did hit, so I know jQuery is successfully calling the method. I stepped through the method and it executed just fine with no errors. I can only assume the error is happening when the jQuery ajax call is returning from the call.

Also, I looked in my event logs just to make sure there wasn't an ASPX error occurring. There is no error in the logs. I also looked at the console. There are no script errors. Anyone have any ideas what I am missing here?

`

© Stack Overflow or respective owner

Related posts about c#

Related posts about jQuery