jQuery Ajax to grab specific PHP variable -
what i'm trying create dashboard jquery ajax calls php page populate fields on dashboard. i've done lots of ajax jquery in past i'm struggling head around problem.
my desired html:
<div id="phase1"> </div> <div id="phase2"> </div> <div id="phase3"> </div>
in php page have 3 variables - $phase1, $phase2 , $phase3. i'd imagine using setinterval keep "live" populate 3 divs respective php variables. bit i'm scratching head how tell php page i'd grab variable $phase1 , distinguish between 3 variables fill right divs. php page called db.php!
can think how construct such ajax call...
in ajax calls set $_get parameter , in php if/elseif/else on it:
$.get("db.php?phase=1", function(data){ alert("data loaded: " + data); }); $.get("db.php?phase=2", function(data){ alert("data loaded: " + data); }); $.get("db.php?phase=3", function(data){ alert("data loaded: " + data); });
php:
switch($_get['phase']) { case '1': //do code , echo break; case'2': //do code , echo break case '3': //do code , echo break; }
Comments
Post a Comment