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 Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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); Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
jacksonmj Posted June 13, 2009 Share Posted June 13, 2009 onclick="showUser(document.getElementById('id').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.