Free Web Hosting Forum
(#1 (permalink))
Old
Member
linegreen04 is on a distinguished road
 
Posts: 51
Join Date: Apr 2012
Default AJAX and MySQL - 05-09-2012, 09:47 AM

Hi Seniors These days i'm working with AJAX and MySQL i have some problem:-
after login to admin there i'm creating new page on clicking new page and there again i'm clicking on HTML on header menu(edit html Source)
and there i'm pasting this code:-
HTML Code:
<script type="text/javascript">
function showUser(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";
  return;
  } 
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
</head>
<body>

<form>
<select name="users"[B][U] onchange="showUser(this.value)[/U][/B]">
<option value="">Select a person:</option>
<option value="1">Peter Griffin</option>
<option value="2">Lois Griffin</option>
<option value="3">Glenn Quagmire</option>
<option value="4">Joseph Swanson</option>
</select>
</form>
<br />
<div id="txtHint"><b>Person info will be listed here.</b></div>
After that when i again go to HTML(edit Html source) then there the above bold and underline code automatically deleted and my code is not working.
however i have also created a file name getuser.php using these codes
PHP Code:
<?php
$q
=$_GET["q"];

$con mysql_connect('localhost''USER MODIFIED BY MODERATOR''PASSWORD MODIFIED BY MODERATOR');
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("ajax_demo"$con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result mysql_query($sql);

echo 
"<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>"
;

while(
$row mysql_fetch_array($result))
  {
  echo 
"<tr>";
  echo 
"<td>" $row['FirstName'] . "</td>";
  echo 
"<td>" $row['LastName'] . "</td>";
  echo 
"<td>" $row['Age'] . "</td>";
  echo 
"<td>" $row['Hometown'] . "</td>";
  echo 
"<td>" $row['Job'] . "</td>";
  echo 
"</tr>";
  }
echo 
"</table>";

mysql_close($con);
?>
The problem is that the onchange="showUser(this.value) isn't working and get deleted automitacally

Thank's

Last edited by d3iti; 05-12-2012 at 09:20 PM.
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Junior Member
Stake is on a distinguished road
 
Posts: 1
Join Date: May 2012
Default 05-12-2012, 06:52 PM

Hey!

First, str may not be standard string, but a String object, so you need to check str this way:
Code:
if (str.toString()==="")
Second, do you really have a whitespace in this?
Code:
document.getElementById("txtHint").innerHTML=xmlht tp.responseText;
xmlht tp => xmlhttp

It should work.

Anyway, if you use Firefox, you can check error messages using this great tool: http://getfirebug.com/
In Chrome, it's a built-in feature, just press F12, also works in IE.

Last edited by Stake; 05-12-2012 at 06:55 PM.
Reply With Quote
(#3 (permalink))
Old
Member
linegreen04 is on a distinguished road
 
Posts: 51
Join Date: Apr 2012
Default Thank's - 05-13-2012, 04:54 AM

Thank's For your Advice
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com