tags:

views:

23

answers:

2

I am using a webservice to return a string called by $.ajax method. How do I get the value ?.

 $.ajax({
            type:"GET",
            url:"ajaxService.asmx/Save",
            data:{},
            success:function(msg){

            //getData(serviceURL, controlLocation,divname,controlID);


            }

How do I get the return value.

+1  A: 

The value is returned at the variable msg.

Read up on $.ajax() at http://docs.jquery.com/Ajax/jQuery.ajax

thephpdeveloper
+1  A: 

The actual return value, as in the content of the request, will be stored in the 'msg' argument in your example. If you want the status code of the request itself (404, 500, etc) you will need to add an extra parameter to your function.

From the jquery documentation about the success function for the ajax call:

" A function to be called if the request succeeds. The function gets passed two arguments: The data returned from the server, formatted according to the 'dataType' parameter, and a string describing the status. This is an Ajax Event.

function (data, textStatus) {
  // data could be xmlDoc, jsonObj, html, text, etc...
  this; // the options for this ajax request
}

"

emills
When I alert(data), i am getting an object, how do i parse this. Also the status is success. Thanks.
Greens
If you have access to Firefox, I would highly recommend the console output commands of firebug. It will allow you to see exactly what's in the object. http://getfirebug.com/console.htmlIf you're expecting the output to actually be a string, you might want to check that you are requesting the correct type of data (json, html, etc)
emills