1

I am trying to call a webservice on my local host which expects a parameter pkId and return the result. WebService runs perfect but when i call from JQuery, it does not return any data. I have tried almost all combinations to set parameter for the Web service (data) part but unable to get any result and the real pain is i don't get any error.

 $.ajax({ type: "POST", url: "http://localhost/WSTest/Service.asmx/AuthorGetById", data: "{pkId :'" + pkId + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { return msg.d; } }); 
3
  • How can you tell if you're not getting any errors if you don't have the error callback implemented? Also, your "success" callback doesn't appear to do anything than return from the callback. I'm assuming you want to do something with the return value, no? Commented Feb 19, 2011 at 18:58
  • Don't post comments in suggested edits; there's an "add comment" button under each answer you can use Commented Feb 20, 2011 at 18:20
  • Have you added [System.Web.Script.Services.ScriptService] in you webmethod for ajax call ? Commented Mar 2, 2011 at 23:10

3 Answers 3

1

Success is invoked as a callback from AJAX. It means that its result is returned to the AJAX jQuery function, not as a return from your function making the AJAX call. You would need to pass result.d off to another function that makes use of it. Have you placed a breakpoint inside your success function to see what value result holds?

For information on consuming web services using AJAX calls, check out:

using jquery to consume aspnet json web services/

Sign up to request clarification or add additional context in comments.

Comments

0

This is not an answer but means to help you reach there.


Even if you have an error you wont get it since you have not handled error at all.
Also worth while to check if your msg has 'd' since its a ASP.NET 3.5+ feature.
Also, dont return msg.d try to alert it.

A sample will be

$.ajax({ type: "POST", url: "http://localhost/WSTest/Service.asmx/AuthorGetById", data: "{pkId :'" + pkId + "'}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (msg) { var datum = msg.hasOwnProperty("d")? msg.d : msg; alert("Success" + datum); } error:function (xhr, ajaxOptions, thrownError){ alert("Error"); } }); 

Comments

0

I found the answer. Actullay i was passing the parameters correctly and noticing the response in firebug but was unable to catch it on success because... my web service method return void. I changed it to return string and boooom it work fine.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.