Radhika Radhika - 5 months ago 12
jQuery Question

Jquery ajax call - how to alert the value from the return object

My requirement is to get the proper value. I got the success alert. result set contains one and only one value. How can I show/alert that value in result?

$.ajax({
type: 'POST',
url: url,
data: getDatawithToken(params),
success: function (result)
{
alert("success");
if(result.d.length>0)
{
alert("success");
}

}
});

Answer

try

$.ajax({
    type: 'POST',
    url: url,
    data: getDatawithToken(params),
    dataType : 'json', // expecting json returned from server
    success: function (result) 
    {
         alert("success");  
         if(result.d.length>0)  
            {
                // access first element 
                alert(result.d[0]);   
            }            

    }
});