i unable print data in first run can print in second run.i want print data in first run itself.
i have 3 files 1. main files sends ajax post,print data(main.php) 2. put sent data session(put.php) 3. print data excel(print.php)
main.php
<?php session_start(); echo '<p class="first">abc</p>'; //dom <p class="first">abc</p> ?> $(document).ready(function(){ var value = $('.first').text(); myfun(); function myfun(){ $.post("put.php", {"content":value},function(data){ console.log(data); }); } window.location.href ='print.php'; });
put.php
<?php session_start(); $_session["content"] = $_post["content"]; ?>
print.php // these file print excel code simple
<?php session_start(); header("content-type:application/xls"); $table = '<table><tr><th>name</th></tr>'; $table .='<tr><td>'.$_session["content"].'</td></tr></table>'; echo $table; header("content-disposition: attachment; filename = new.xls"); ?>
please me,thanks in advance.
why
js won't stop exec when ajax not complete, should redirect after ajax complete make sure $_session["content"]
has set
fix
change
$(document).ready(function(){ var value = $('.first').text(); myfun(); //i missing function myfun(){ $.post("put.php", {"content":value},function(data){ console.log(data); }); } window.location.href ='print.php'; });
to
$(document).ready(function(){ var value = $('.first').text(); myfun(); //i missing function myfun(){ $.post("put.php", {"content":value},function(data){ console.log(data); window.location.href ='print.php'; }); } });
Comments
Post a Comment