Solved

Clear Div before Ajax loads

Posted on 2010-08-27
3
696 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

772 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