JSON will probably be the easiest here:
$.ajax({
type: "POST",
data: { id: someIDVariable },
url: "ajax/css.php",
success: function (result) {
$('#bg').css('background-color', result.bg);
$('#font').css('font-color', result.font);
}
});
Or a shorter form using $.getJSON()is the GET option:
$.getJSON("ajax/css.php", { id: someID }, function (result) {
$('#bg').css('background-color', result.bg);
$('#font').css('font-color', result.font);
});
Then in PHP:
eacho json_encode(array('font'=>$font,'bg'=>$bg));
//which will echo this format: { "font": "Arial", "bg": "#000000" }
source
share