Greens
Greens

Reputation: 3057

How to get return from $.ajax from a webservice

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.

Upvotes: 0

Views: 1041

Answers (3)

Atul Singhal
Atul Singhal

Reputation: 11

$.ajax({
    type:"GET",
    url:"ajaxService.asmx/Save",
    data:{},
    success:function(msg){
        // if you use 2.0 framework of .net then you have to make object
        var s = eval('(' + msg + ')');

        // if you use 3.5 framework of .net then you have to make object
        var s = eval('(' + msg.d + ')');

        //then you can take value from s.
    }
})

Upvotes: 1

emills
emills

Reputation: 521

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
}

"

Upvotes: 1

mauris
mauris

Reputation: 43619

The value is returned at the variable msg.

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

Upvotes: 1

Related Questions