php - changing background color through AJAx jquery? -
scenario: users have thier own profile pages different background colors , fonts, want retrieve colors exmaple user using ajax. i.e.
$.ajax({ type: "post", data: "id", url: "ajax/css.php", success: function (bg,font) { $('#bg').css('background-color', 'bg'); $('#font').css('font-color', 'font'); }
ajax/css.php page
<?php //retrieve background , font data database id(userid). // bit im stuck here, shall echo reuslts or return them :~ ?>
an example great guys :))
json easiest here, this:
$.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 shorter form using $.getjson()
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 echo format: { "font": "arial", "bg": "#000000" }
Comments
Post a Comment