How to convert ajax retrieved object to string in jquery How to convert ajax retrieved object to string in jquery json json

How to convert ajax retrieved object to string in jquery


You have the scope for the variable markers inside the post method, try doing it like this:

var markers = '';$.post('maps1.php', {}, function (data) {    alert(data);    markers = JSON.stringify(data);}, "json");alert(markers)


$.ajax should do this way:

     var marker;     $.ajax({        url:'maps1.php',        data:{},        type:'POST',        dataType:'json',        success:function(data){            alert(data);            marker = JSON.stringify(data);        },        complete:{            alert(marker);        }   });

and $.POST should be like this:

   $.post('maps1.php',{},function(data){       alert(data);   },"json").done(function(data){       markers=JSON.stringify(data);       alert(markers);   });

but i prefer to use $.ajax()


ajax string syntax below:

 var marker; $.ajax({    url:'maps1.php',    data:{},    type:'POST',    dataType:'json',    success:function(data){        alert(data);        marker = JSON.stringify(data);    },    complete:{        alert(marker);    }});