Eggzorcist Posted June 6, 2009 Share Posted June 6, 2009 Alright, heres my JS code. All works but one thing. It seems like my PHP code isn't receiving any GET information but I'm having trouble seeing how it isnt. // JavaScript Document var xmlhttp; function showUser(str) { xmlhttp=GetXmlHttpObject(); if (xmlhttp==null) { alert ("Browser does not support HTTP Request"); return; } var url="trackeractions.php"; url=url+"?id="+str; //url=url+"&sid="+Math.random(); xmlhttp.onreadystatechange=stateChanged; xmlhttp.open("GET",url,true); xmlhttp.send(null); } function stateChanged() { if (xmlhttp.readyState==4) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } function GetXmlHttpObject() { if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari return new XMLHttpRequest(); } if (window.ActiveXObject) { // code for IE6, IE5 return new ActiveXObject("Microsoft.XMLHTTP"); } return null; } I'm not that good in AJAX. This is for my media design class. Thanks Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/ Share on other sites More sharing options...
rv20 Posted June 6, 2009 Share Posted June 6, 2009 Are you calling it from a form or what? Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-850641 Share on other sites More sharing options...
Eggzorcist Posted June 7, 2009 Author Share Posted June 7, 2009 Well I want to be able to retrieve the GET in my php, I've tested the PHP and it works, but it cannot retrieve the $_GET['id']; So I'm guessing its the javascript that isn't producing a $_GET well. What can I do? Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-850817 Share on other sites More sharing options...
Ken2k7 Posted June 7, 2009 Share Posted June 7, 2009 Can you post the PHP script trackeractions.php as well? Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-850874 Share on other sites More sharing options...
alco19357 Posted June 7, 2009 Share Posted June 7, 2009 Does the internet browser you're using support ajax like you asked in the code? I know it's a silly question, but typically that is the problem. Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-850887 Share on other sites More sharing options...
Eggzorcist Posted June 7, 2009 Author Share Posted June 7, 2009 here's the PHP code. <?php $dbhost = "localhost"; $dbuser = "root"; $dbpass = ""; $dbname = "tgj4u"; mysql_connect($dbhost, $dbuser, $dbpass); mysql_select_db($dbname) or die(mysql_error()); $id = $_GET['id']; $id = mysql_real_escape_string($id); $query = "SELECT * FROM maildata WHERE id = '$id'"; $qry_result = mysql_query($query); if (mysql_num_rows($qry_result)){ while($info = mysql_fetch_assoc($qry_result)){ echo "Sent by: " . $info['sender'] . "<br>"; echo "Recipient: " . $info['recipient'] . "<br>"; echo "Departed: " . $info['depart'] . "<br>"; echo "Satus: " . $info['depart'] . "<br>"; echo "Current Location: " . $info['currentlocation'] . "<br>"; echo "Arrival Location: " . $info['finallocation'] . "<br>"; echo "Expected on: " . $info['expected'] . "<br>"; } } else { echo "<p>No data was found with that ID.</p>\n"; } ?> I've tried with both mizila firefox and internet explorer. Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-850913 Share on other sites More sharing options...
Eggzorcist Posted June 7, 2009 Author Share Posted June 7, 2009 I would like to also add that, if I go to the php page on its own and add /trackeractions.php?id=55583 a correct id to the URL it works. Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-850914 Share on other sites More sharing options...
Eggzorcist Posted June 10, 2009 Author Share Posted June 10, 2009 Does anyone have an alternate script which does the same thing? Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-853139 Share on other sites More sharing options...
Stooney Posted June 10, 2009 Share Posted June 10, 2009 What is the end URL that's generated before the request? If you don't know then after this line: url=url+"?id="+str; add this: alert(url); Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-853146 Share on other sites More sharing options...
Eggzorcist Posted June 12, 2009 Author Share Posted June 12, 2009 I did alert(url) and it seem slike its not passing to the get becuase it's not alerting whatsoever... However, it is getting data from "trackeractions.php"; its a little strange Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-854410 Share on other sites More sharing options...
Eggzorcist Posted June 12, 2009 Author Share Posted June 12, 2009 ah here is there error: <form> Package ID:<input name="id" type="text" id='id' value="f" size="10" maxlength="10" /> <br /> <input type='button' onclick='showUser(this.value)' value="Track"/> </form><br /> What is being tracker is the wrong value. I want it to pickup the value to value="f" but what it is picking up now is value="track" which is the button value, what is the command to change it to the text box? Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-854414 Share on other sites More sharing options...
jacksonmj Posted June 13, 2009 Share Posted June 13, 2009 onclick="showUser(document.getElementById('id').value)" Link to comment https://forums.phpfreaks.com/topic/161156-solved-using-get-isnt-working/#findComment-855229 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.