I am new to AJAX and am kind of confused by what PHP passes back to the jQuery. So you have an AJAX function like this:
$.ajax({ url: '/my/site',
data: {action: 'test'},
type: 'post',
success: function(output) {
alert(output);
}
});
(I took this from ajax another StackOverflow page.)
But on various other resources they will have the success section look like this:
success: function(data) {functionfoocommandshere}
I am just confused as to what dictates the naming of this variable? If the PHP ultimately echoes an array:
echo $myVar;
How can I get this from the AJAX?
datavariable of thesuccessmethod will hold anything youechoin PHP. You can not pass an array directly; you have to convert it to JSON first.echoan array in PHP, you canprint_rorvar_dumporserializeit, butechois meant for strings or ints, etc.