kaz3 Posted June 6, 2008 Share Posted June 6, 2008 On my site I am using AJAX so that when a user clicks a link, the file is downloaded and the number in the download number file(a txt file) is increased(later it will be a database). The problem is that sometimes it works in different browsers and it can never add to two files on the same page without refreshing. Add download function: function addDownload(name){ var xmlHttp=GetXmlHttpObject(); if (xmlHttp==null){ alert ("Your browser does not support AJAX!"); } var dlid=document.getElementById("downloads_"+name); var dl=dlid.innerHTML; dl=parseInt(dl); dl+=1; dlid.innerHTML=dl+" downloads";//Change the number on the page var url="ajax/add_download.php"; url+="?name="+name; url+="&sid="+Math.random(); xmlHttp.open("GET",url,true); xmlHttp.send(null); } PHP add download function: <?php $name=$_REQUEST['name']; echo $name."<br>"; $file="../files/downloads/$name.txt"; $f=fopen($file,"r"); $downloads=fread($f,filesize($file)); fclose($f); echo "old: ".$downloads."<br>"; $downloads++; $f=open($file,"w"); fwrite($f,$downloads); fclose($f); echo "new: ".$downloads; ?> The downloads do get written if I just go to the add_download.php page, so thats not the problem. Any ideas? Link to comment https://forums.phpfreaks.com/topic/109021-ajax-add-download/ Share on other sites More sharing options...
aseaofflames Posted June 12, 2008 Share Posted June 12, 2008 on the php page have you tried $_GET['name'] instead of $_REQUEST['name']? Link to comment https://forums.phpfreaks.com/topic/109021-ajax-add-download/#findComment-564056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.