Cool Sporty
Cool Sporty

Reputation: 311

Ajax div loading

I am loading a div with ajax.. My Code Is.

Code:

<script type="text/javascript">
function showvalue(str)
{


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)
    {

    var myString = xmlhttp.responseText; 
    document.getElementById("div2").innerHTML=myString;



   }
  }
xmlhttp.open("GET","test.php?u="+str,true);
xmlhttp.send();
}

When The User Click On the button. It is showing a div with some content in it. When the user again click on the button., the query again select some piece of data from database. The Previous Content From the div is lost & new content is inserted into the div. But i want to load both previous data & new data into that div. Is there anyway to save the previous div state? Please help me

Upvotes: 0

Views: 159

Answers (1)

Satya
Satya

Reputation: 8881

change this line

document.getElementById("div2").innerHTML=myString;

to

document.getElementById("div2").innerHTML+=myString;

Upvotes: 4

Related Questions