Post javascript variables to separate .PHP file (Using Ajax?) -
i have 2 files, 1 runs calculations in php once , stores them variables in javascript. second file holds mysql query sent database. how can send javascript variables first file, second file , store them variables.
-i loading second .php file using .load() function. not refreshing , re- directing second .php file.
is possible out ajax? if possible ajax, how set (new ajax) ?
$("#st").click(function() { var s = $("#st").val(); var = $("#aa").val(); var t = ((s*1)*(a*1)+(a*1)*(1/3)).tofixed(2); var c = (t*95).tofixed(2); var text = $('#st').children("option:selected").text(); document.getelementbyid('tim').innerhtml ='<p>'+ t +' </p>'; document.getelementbyid('obj').innerhtml ='<p>'+ text +'</p>'; document.getelementbyid('tot').innerhtml ='<p>$'+ c +'</p>'; }); var customer = <?php echo json_encode($q);?>; var dr= <?php echo json_encode($o);?>; var pd = <?php echo json_encode($p);?>; var qp = <?php echo json_encode($a);?>; var qs = <?php echo json_encode($r);?>; var cam = <?php if($camera==1){ $cameraoutput = "xl"; echo "xl"; } if($camera==2){ $cameraoutput = "sl"; echo "sl"; } ?>;
ajax acronym asynchronous javascript , xml. if want run second php file without redirecting it, can use ajax because run second php file 'in background'. ajax jquery extremely easy use aswell.
taken http://api.jquery.com/jquery.ajax/
example: save data server , notify user once it's complete:
$.ajax({ type: "post", url: "some.php", data: { name: "john", location: "boston" } }).done(function( msg ) { alert( "data saved: " + msg ); });
Comments
Post a Comment