Jump to content

[SOLVED] 1 Request, Multiple DIVs...?


suttercain

Recommended Posts

Hi everyone,

 

I am currently making an AJAX request that queries the MySQL database and loads the content into a DIV. My question is how do I load additional content into a seperate DIV based on the same original request?

 

Here is a sample but I was unable to emulate:

http://www.seopher.com/demos/ajax-multi-request/

 

Here is my code:

 

HTML

<a href="java script:showUser('<?php echo $row['executive_order'];?>')"><?php echo $row['executive_order']; ?>

<div id="content1>Content Loads Here</div>

<div id="content2>Want content to also load here</div>

 

JavaScript

// JavaScript Document
var xmlHttp

function showUser(str)
{ 
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="select.php"
url=url+"?q="+str
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged 
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}

function stateChanged() 
{ 
if(xmlHttp.readyState == 0)
{
document.getElementById('content1').innerHTML = "Sending Request...";
}
if(xmlHttp.readyState == 1)
{
document.getElementById('content1').innerHTML = "Loading Response...";
}
if(xmlHttp.readyState == 2)
{
 document.getElementById('content1').innerHTML = "Response   Loaded...";
}
if(xmlHttp.readyState == 3)
{
 document.getElementById('content1').innerHTML = "Response Ready...";
}

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{ 
document.getElementById("content1").innerHTML=xmlHttp.responseText 
} 
}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
//Internet Explorer
try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
}
return xmlHttp;
}

 

PHP

<?php
if (isset($_GET['q'])) {
require('../../../../vdb/includes/connection.php');
$q=$_GET["q"];
$statement = "SELECT * FROM device
				INNER JOIN device_eo ON (  device.device_id = device_eo.device_id )
				INNER JOIN eo ON ( device_eo.executive_order = eo.executive_order )
				INNER JOIN eo_engine_family ON ( eo.executive_order = eo_engine_family.executive_order )
				INNER JOIN engine_family ON ( eo_engine_family.engine_family_name = engine_family.engine_family_name )
				WHERE eo.executive_order = '".$q."'
				ORDER BY engine_family.engine_year, engine_family.engine_mfr, engine_family.engine_family_name";

$results = mysql_query($statement) or die(mysql_error());
while ($row = mysql_fetch_array($results)) {
  echo $row['engine_family_name']. "<br />";
}
}
?>

 

Any help would be great. Thanks in advance.

 

-SC

Link to comment
Share on other sites

The page you referenced only makes one AJAX call when you click the link. But, What it returns is the following string:

pigeon###RAWR###dog###RAWR###kitten###RAWR###

I assume they then split on '###' with JavaScript and assign it to the proper DIVs.

 

Does that help?

Link to comment
Share on other sites

Thanks for the reply. Yeah what he did in his tuorial, http://www.seopher.com/articles/multiple_ajax_responses_with_1_request_mootools_and_php, was to do a ginle query and use an array.

 

What I would like to do is similar... but different. I have one php file that performs a mysql query. I would also like a separate php file to perform a separate query, using the same value from the original link. So the user clicks on a link the first PHP file is queried and Loaded into DIV1. At the same time, based on that same click, the second PHP file is queried and that content is loaded into DIV2.

 

Hope I am making sense. It's hard for me to spit it out, sorry.

 

SC

Link to comment
Share on other sites

i would use jQuery...it will make your life a lot easier...at the top of the page, in the <head> tag, put:

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

then, change your JS to:

// JavaScript Document
function showUser(str)
{
  $('#content1').load("select.php?q="+str);
  $('#content2').load("select2.php?q="+str);
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.