javascript - Passing values from jQuery to PHP in same page instantly -
i have written php programme confirm deletion of info through jquery confirm message (refer: http://rathur.fr/jquery/msgbox/) , record result same page instantly. if page refreshes, it'll homecoming state previous.
the part of line below:
print " <script type='text/javascript'> $(document).ready(function(){ $.msgbox('<br/>are sure want delete selected record database?', { type : 'confirm' }, function(result){ $('#output').text(result); var output = result; }); }); </script>"; i want result of action button php variable instantly, below (just trial):
$x = $_session['output']; or $x = $_post['output']; or $x = print "<div id=\"output\"></div>"; or $x = some_function(output); please help me, or suggest if there other improve options.
here simple ajax phone call php file event : click on button.
javascript client side :
$("body").on("click", "#mybutton", function() { var mydata = $("#form").serialize(); $.ajax({ type: "post", url: "/api/api.php", data: {data : mydata}, timeout: 6e3, error: function(a, b) { if ("timeout" == b) $("#err-timedout").slidedown("slow"); else { $("#err-state").slidedown("slow"); $("#err-state").html("an error occurred: " + b); } }, success: function(a) { var e = $.parsejson(a); if (true == e["success"]) { $("#action").html(e['message']); // here want, callback php response content in html dom } } }); homecoming false; }); next in php code after success function :
if ($result) { echo json_encode(array( 'success' => true, 'msg' => "nice callback php sent client side ajax call" )); } javascript php jquery msgbox
No comments:
Post a Comment