Solved

Clear Div before Ajax loads

Posted on 2010-08-27
3
698 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
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.

749 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