Ajax PHP wont retrieve address bar variable -
this question has answer here:
my current website address reads: www.mysite.com/index.php?user=123
i click link active ajax page open. ajax page contains following:
$usernum = $_get["user"]; $result = mysql_query("select * persons user = $usernum");
this produces error:
warning: mysql_fetch_array() expects parameter 1 resource, boolean given in c:\program files (x86)\ampps\www\social2\profile\indexbasics.php on line 29
no error ocurrs if hard code in user number though, refuses address bar variable.
help? advice?
----- added info ------
<script> window.onload = function () { var basics = document.getelementbyid('basics'), favorites = document.getelementbyid('favorites'); basics.onclick = function() { loadxmldoc('indexbasics'); var otherclasses = favorites.classname; if (otherclasses.contains("active")) { basics.classname = 'statusoptionactive'; favorites.classname = 'statusoption'; } } favorites.onclick = function() { loadxmldoc('indexfav'); var otherclasses = basics.classname; if (otherclasses.contains("active")) { favorites.classname = 'statusoptionactive'; basics.classname = 'statusoption'; } } function loadxmldoc(pagename) { var xmlhttp; if (window.xmlhttprequest) {// code ie7+, firefox, chrome, opera, safari xmlhttp=new xmlhttprequest(); } else {// code ie6, ie5 xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readystate==4 && xmlhttp.status==200) { document.getelementbyid("centrecont").innerhtml=xmlhttp.responsetext; } } xmlhttp.open("get","../profile/" + pagename + ".php",true); xmlhttp.send(); } } </script>
so you're saying on www.mysite.com/index.php?user=123
when click on button (or whatever fire ajax event), load different url, can www.mysite.com/myajaxpage.php
.
in case, may have forget pass user parameter ajax request. can't access $_get['user']
in myajaxpage.php
because isn't defined in url.
code example
if you're using jquery, can trick:
$.urlparam = function(name){ var results = new regexp('[\\?&]' + name + '=([^&#]*)').exec(window.location.href); return results[1] || 0; } // .... $.post('myajaxpage.php', {'user': $.urlparam('user')}, function(data) { // stuff });
edit: author uses vanilla js, example pointless.
Comments
Post a Comment