Jump to content

Multiple requests


bradynorman

Recommended Posts

Hi,

I'm a newbie to AJAX but i thought that i would attempt to incorporate a little into a web-site that i'm developing. Well after just a few hours i'm like WOW i'm hooked.

Anywho - i would like to develop the following page a little further but am stuck with making multiple requests to different php pages that are retreiving sql data for me.

PLEASE if anyone can offer any assistance iwould be eternally grateful - i have incidentally been browsing the forums for an answer......

 

In the header of my page ship_single.php

 

<script src="showSingleAdr.js"></script>

 

details are:

 

var xmlHttp

function showSingleAdr(str)

{

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

return

}

var url="ajax_single_address.php"

url=url+"?postcode="+str

url=url+"&sid="+Math.random()

xmlHttp.onreadystatechange=stateChanged

xmlHttp.open("GET",url,true)

xmlHttp.send(null)

}

 

function stateChanged()

{

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{

document.getElementById("Address").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;

}

 

The following

 

<input name="postcode" type="text" id="postcode" onblur="showSingleAdr(this.value)" value="<?php echo $_GET['Postcode']; ?>" />

 

updates <div id="Address"></div> with data retrieved from the ensuing mysql query. I'm happy with that perhaps the coding isn't perfect though.....

 

On the same form i now want to use AJAX to retreive a stock quantity - the coding is similar:

 

 

<script src="showSingleAdr.js"></script>

 

the details of this file....

 

var xmlHttp

 

function showStock(str)

{

xmlHttp=GetXmlHttpObject()

if (xmlHttp==null)

{

alert ("Browser does not support HTTP Request")

return

}

var url="ajax_stock.php"

url=url+"?pn="+str

url=url+"&sid="+Math.random()

xmlHttp.onreadystatechange=stateChanged

xmlHttp.open("GET",url,true)

xmlHttp.send(null)

}

 

function stateChanged()

{

if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")

{

document.getElementById("Stock").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;

}

 

and the coding to select this is

 

                    <select name="pn" id="pn" onchange="showStock(this.value)" >

                    <option>Select Part</option>

                    <?php

mysql_select_db($database_grcdb, $grcdb);

                    $query="SELECT pn FROM parts ORDER BY pn ASC";

                    $result=mysql_query($query);

                    while(list($pn)=mysql_fetch_row($result)) {

                        echo "<option value=\"".$pn."\">".$pn."</option>";

                    }

                    ?>

</select>

 

results sent to

 

<div id="Stock"></div>

 

Individually these work, however together they fall over.....

Where am i going wrong????

 

thanks in advance

cheers

Mike

 

 

Link to comment
https://forums.phpfreaks.com/topic/122908-multiple-requests/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.