0

I have created a Webmethod in ASP.NET, and trying to access that through jQuery AJAX. When I call the Webmethod through browser it's giving a JSON result, but when I call that through jQuery AJAX it's giving "204 no content" in Firebug of Firefox. (My webmethod is in one domain and jQuery AJAX code is in other domain).

JQuery Ajax Code:

 $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: "http://localhost:1177/api/authentication/getusermenu?roleid=1",
           processData: true,
            dataType: "jsonp",
            success: function (msg) {
                alert(msg.d);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                var data = $.parseJSON(jqXHR.responseText);
                alert(data);
            }
        });

Firebug Output:

"Reload the page to get source for: (URL)"

icktoofay
  • 126,289
  • 21
  • 250
  • 231
Srivastav
  • 361
  • 3
  • 15

1 Answers1

0

Try the below: 1. if the webmethod is in the same application then no need to give localhost or anything.if the web method in any other machine and it is accessible then provide the url: "http:///..." rather than localhost:portNo. 2. dataType: "json",

full example like below:

 $.ajax({
            type: "POST",
            url: "ABC.aspx/GetUserMenu?roleid=1",
            data: {},
            contentType: "application/json; charset=utf-8",
            dataType: "json",
             success: function (msg) {
            alert(msg.d);
        },
        error: function (jqXHR, textStatus, errorThrown) {
            var data = $.parseJSON(jqXHR.responseText);
            alert(data);
        }

        });
Hrqls
  • 2,944
  • 4
  • 34
  • 54
Sanjay
  • 1