Solved

Clear Div before Ajax loads

Posted on 2010-08-27
3
697 Views
Last Modified: 2012-05-10
I am using the ajax script below to populate the div "txtHint"...The script returns everything that is echoed in the update_chauffer.php page. I need to clear the div "txtHint" before ajax loads and displays the information again. Basically I am inserting information into mysql then running a query to display information based on the query so I am continually adding to the query results...Thanks
<script type="text/javascript">
function UpdateChauffer(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","update_chauffer.php?ride=<? echo $_GET['id']; ?>&q="+str,true);
xmlhttp.send();
}
</script>

Open in new window

0
Comment
Question by:brad0525
  • 2
3 Comments
 
LVL 11

Expert Comment

by:Amar Bardoliwala
ID: 33540733
Hello brad0525,

Your script seems fine currently.

Can you please tell exactly  what problem are you getting?

Thanks.

Amar.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 33540853
Currently you do the job only if str is empty :

function UpdateChauffer(str)
{
if (str=="")
  {
  document.getElementById("txtHint").innerHTML="";

we may do it all time :

function UpdateChauffer(str)
{
  document.getElementById("txtHint").innerHTML="";
if (str=="")
  {

If you don't see the content cleared this is because you're don't clear the right div, perhaps you more than one or need to clear a parent div
0
 
LVL 82

Expert Comment

by:leakim971
ID: 33659427
You're welcome! Thanks for the points!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

jQuery is a JavaScript library that greatly simplifies JavaScript programming. AJAX is an acronym formed from "Asynchronous JavaScript and XML."  AJAX refers to any communication between client and server, when the human client does not observe a…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question