Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

I have this code to display the data retrieved from DB in accounts_view.php:

<script type="text/javascript">
function showPrice(str)
{
if (str=="")
  {
  document.getElementById("sender_price").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("sender_price").innerHTML=xmlhttp.responseText;
    }
  }
xmlhttp.open("GET","?action=account&q="+str,true);
xmlhttp.send();
}
</script>

I have problem in the below line :

xmlhttp.open("GET","?action=account&q="+str,true);

Just to explain to you I have index.php and have many cases there, I have

case "account" :

$q=$_GET["q"];

//code is here to get data from db and return with result..

include($_STR_TEMPLATEPATH."/account_view.php");

break;

So, When I am redirecting to ?action=account&q=str in the account_view.php

it displays the page again, so I will have 2 pages over each other.

I hope the problem is clear to you :)

Thanks and Regards,

share|improve this question
up vote 0 down vote accepted

I would recommend using jquery to retrieve data from a database if you are wanting to use ajax. All the browser incompatibilities are already accounted for and you won't have to bother coding for all the issues you will encounter trying to accomplish this by hand. basically why re-invent the wheel that is already perfectly created.

Here is an example of my code using jquery and how easy it is to use.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>some title</title>
<link href="customize.css" rel="stylesheet" type="text/css" media="screen" />
<link href="css/black-tie/jquery-ui-1.8rc3.custom.css" rel="stylesheet" type="text/css" media="screen" />
<script type="text/javascript" src="jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="jquery-ui-1.8rc3.custom.min.js"></script>
<script type="text/javascript">
   function ShowActive(inputString){
     //gives visual that something is happening
     $('#Sresults').addClass('loading');
     //send your data to a php script here i am only sending one variable
     //if using more than one then use json format
     $.post("allactive.php", {queryString: ""+inputString+""}, function(data){
       if(data.length >0) {
         //populate div with results
         $('#Sresults').html(data);
         $('#Sresults').removeClass('loading');
       }
     });
   }
</script>
</head>
<body>
  put your form here ....
  <div id="Sresults" name="Sresults"></div>
</body>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.