Rafay
Rafay

Reputation: 31043

cannot get the web service response

i surely an committing a very lame mistake but couldn't figure out where...

here is my web method

 [WebMethod]
        [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
        public int Add(int x, int y) {

            return x + y;

        }

and im calling it via ajax like this

 $.ajax({
            type: "GET",
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            data: { x: 4, y: 5 },
            url: 'http://localhost:14436/Service1.asmx/Add',
            success: function (data) {
                alert('success');
                var d = $(data);
                console.log(d);        


            }
        });

the problem is i cannot get the returned data in success,

in fiddler its showing {"d":9} but i keep on getting data empty... what am i doing wrong here... TIA enter image description here

Edit

my web service is at http://localhost:14436/Service1.asmx and my web application from which im accessing the web service is located at http://localhost:3587/

so i guess this makes it a cross domain request?

Upvotes: 0

Views: 1144

Answers (1)

Kamyar
Kamyar

Reputation: 18797

try the following function:

function AjaxSucceeded(result) 
{
  alert(result.d);
}  

still not getting any result?
UPDATE:
You can read more about the .d wrapper at:
http://encosia.com/2009/02/10/a-breaking-change-between-versions-of-aspnet-ajax/

Here's the exact sample as what you're trying to achieve:
http://www.joe-stevens.com/2010/01/04/using-jquery-to-make-ajax-calls-to-an-asmx-web-service-using-asp-net/

Upvotes: 1

Related Questions