0

I am new to ajax and javascript.

I have the following web method in a page called people.aspx in the root of my web porject:

[System.Web.Services.WebMethod]
public static string RenderDetails()
{
    return "Is it working?";
}

I'm attempting to access the web method via an Ajax call from the people.aspx page. I have the following ajax call on the click event of a div:

$("div.readonly").click(function (e) {
    e.stopPropagation();
    $.ajax({
      type: "POST",
      async:false,
        url: "people.aspx/RenderDetails",                   
        dataType: "json",
        beforeSend: function () {
            alert("attempting contact");
        },
        success: function (data) {
            alert("I think it worked.");
        },
        failure: function (msg) { alert("Sorry!!! "); }
    });

    alert("Implement data-loading logic");
});

I'm not receiving any errors in the javascript console, however, the ajax call also does not hit the web method. Any help will be appreciated.

Thanks!

INDIA IT TECH
  • 1,902
  • 4
  • 12
  • 25
Code_Ninja
  • 35
  • 10

1 Answers1

0

Try change the type to GET not POST (this is probably why your webpage isn't getting hit). Also your failure parameter is incorrect, it should be error. Expand it to include all parameters (it will provide more information). In short, change your entire AJAX query to this:

$.ajax({
    type: "GET",
    async:false,
    url: "people.aspx/RenderDetails",                   
    dataType: "json",
    beforeSend: function () {
        alert("attempting contact");
    },
    success: function (data) {
        alert("I think it worked.");
    },
    error: function (jqXhr, textStatus, errorThrown)
        alert("Sorry!!! ");  // Insert breakpoint here
    }
});

In your browser, debug the error function. The parameters (particularly jqXHR) contain a LOT of information about what has failed. If you are still having more problems, give us the information from jqXHR (error string, error codes, etc).

Ian
  • 1,475
  • 2
  • 15
  • 31
  • Thanks very much for the information. Changing from POST to GET did the trick. Apologies for the late reply, got side tracked with other projects. – Code_Ninja Mar 21 '16 at 15:23