javascript - AJAX variable are not reading from PHP file? -



javascript - AJAX variable are not reading from PHP file? -

this javascript holds function save file.

function savemap() { var xmlhttp; if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } map = document.getelementbyid("sectortablemap").innerhtml; info = '<table id="sectortablemap">'; info += map; info += '</table>'; document.getelementbyid("sectortablemap").innerhtml = data; //alert("done"); //alert(data); if(filename=="lastsave - rename") { homecoming alert("please set file name under [config]"); } else { //alert(data); //alert(user); //alert(filename); xmlhttp.open("post","http://pardustools.comuf.com/savemap.php?t="+math.random(),true); xmlhttp.send('map='+data+'&user='+user+'&filename='+filename); //alert(data); //alert(user); //alert(filename); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { //return alert("file has been saved!"); homecoming alert(xmlhttp.responsetext); } } }

this files posted too.

<?php $user = strtolower($_post['user']); $map = $_post['map']; $filename = "savedmaps/".$user."/".$_post['filename'].".html"; file_put_contents($filename,$map); echo $filename."<br />".$map; ?>

this output receive on php file.

savedmaps//.html

it should more this

savedmaps/randomname/filename.html

edit:

to set user.

user = "<?php $cookie = $_cookie['mapperlogauth']; echo strtolower($cookie['user']);?>";

to set data... under savemap() function , starts map.

you using php's $_post get, you're not posting variables, should utilize $_get in situation, or alter xmlhttp send post properly. edit missing content type header successful post

edit should aware there limit on how much can send through using technique you're using. (which get, not post, though specify it)

i'd recommend looking jquery cross-browser compatibility , ease of use.

edit

here's code allow pick via post:

xmlhttp.open("post","ajax_test.asp",true); xmlhttp.setrequestheader("content-type","application/x-www-form-urlencoded"); xmlhttp.send("fname=henry&lname=ford");

javascript php ajax

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -