n00bert Posted September 19, 2008 Share Posted September 19, 2008 I can't seem to pass my cid variable to my getPage() function. But here I think it will be easier to help if you can see what i'm talking about so here is my function. function getPage(intPage){ var xmlHttp; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); } catch (e){ // Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); } catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ window.location="noajax.html"; return false; } } } xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4){ document.getElementById('content').innerHTML=xmlHttp.responseText; }else{ document.getElementById('content').innerHTML='<center><img src="images/loading.gif" alt="Loading" style="border:0px;"/><br />Loading, Please Wait...</center>'; } } switch(intPage){ case 1: xmlHttp.open("GET","news.php",true); xmlHttp.send(null); break; case 2: xmlHttp.open("GET","about.php",true); xmlHttp.send(null); break; case 3: xmlHttp.open("GET","viewgallery.php",true); xmlHttp.send(null); break; case 4: xmlHttp.open("GET","services.php",true); xmlHttp.send(null); break; case 5: xmlHttp.open("GET","contact.php",true); xmlHttp.send(null); break; case 6: xmlHttp.open("GET","parts.php",true); xmlHttp.send(null); break; case 7: default: xmlHttp.open("GET","news.php",true); xmlHttp.send(null); } } and here is the link i'm trying to pass <a href='javascript:getPage(3)?cid=".$row[0]."'>".$row[1]."</a> I'm pretty new to javascript and ajax...too be honest i'm still unsure on what ajax is. sry if i left out any key details. I'm pretty tired right now. So just let me know if you need anything else to help. thanks, n00b Quote Link to comment Share on other sites More sharing options...
xenophobia Posted September 19, 2008 Share Posted September 19, 2008 Is this work? <a href='javascript:getPage(" . $row[0] . ")'> Quote Link to comment Share on other sites More sharing options...
n00bert Posted September 19, 2008 Author Share Posted September 19, 2008 no that wouldn't work because the page it needs to get is "3" which is actually the viewgallery.php. And viewgallery.php the the file that contains the link. Quote Link to comment Share on other sites More sharing options...
php.ajax.coder Posted September 20, 2008 Share Posted September 20, 2008 Just use the GET method by adding the value to the page name e.g. news.php?value=4 From the file use <?Php echo $_GET['value']; ?> to get the value Quote Link to comment Share on other sites More sharing options...
php.ajax.coder Posted September 20, 2008 Share Posted September 20, 2008 Try this script <script type="text/Javascript"> var xmlHttp; try{ // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch (e){ // Internet Explorer try{ xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch (e){ try{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch (e){ window.location="noajax.html"; return false; } } } function pageRequest(page){ xmlhttp.open('GET', page); xmlHttp.onreadystatechange=function(){ if(xmlHttp.readyState==4){ document.getElementById('content').innerHTML=xmlHttp.responseText; }else{ document.getElementById('content').innerHTML='<center><img src="images/loading.gif" alt="Loading" style="border:0px;"/><br />Loading, Please Wait...</center>'; } } xmlhttp.send(null); } </script> Just use the GET method by adding the value to the page name EXAMPLE news.php?value=4 <a href='javascript:pageRequest("news.php?value=4")'> From the file use <?Php echo $_GET['value']; ?> to get the value Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.