How to return multiple data using jquery, json, ajax and php.
$.ajax({
url:'ajax.php',
type:'post',
data:{function:'postAnswer', questionID:$('#questionID').val(), answer:$('#answer').val()},
success:function(data)
{
alert(data);
location.reload();
}
});
Use double quotes for json value or it would be variable change like this
data:{function:"postAnswer", questionID:$('#questionID').val(), answer:$('#answer').val()},
first of all, You need to json encode() all the data which was returned in ajax.php You need to encode it, at that page before return.
echo json_encode(data variable name in ajax page);
then you need to use this code at the success phase
$.ajax({
url:'ajax.php',
type:'post',
data:"passing_dataname"+passing_data,
success:functiondata, textStatus, jqXHR)
{
var answer=jQuery.parseJSON(data);
alert(answer);
}
});