开发者

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

cannot get the web service response

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:开发者_C百科//localhost:3587/

so i guess this makes it a cross domain request?


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜