Asked by duncanb7
at 2024-11-16 12:01:58
Point:500 Replies:4 POST_ID:828427USER_ID:11059
Topic:
Asynchronous Javascript and XML (AJAX);JavaScript;PHP Scripting Language
I've a html table with three products, A,B,C and I would like to update every product
in myajax.html file at table row "Today" by AJAX with xmlhttp open from the URL file of
"http:www/mywebsite.com/ product-data.htm which is stored all product left for Today only
and is always changed depend on market need
I start to write myajax.html for Ajax update . And I found problem at
document.getElementbyID("product-A").innerHTML = ajaxRequest.responseText to grab
the data from product-data.htm , I mean I don't know to specifiy the location I need in
production-data.htm
Please advise to get update data for table (row2, col2), (row2, col3), row2, col4)
Below code is my ajax.html with the table and attached code is pruduct-data.htm
which is stored or saved all production data
I read the site, somepeoplesay it is better to use XML format instead of html for Ajax open URL and
some say it is better to use php to seach AJax data. So what is better, please also advise
Thanks a lot
Duncan
************myajax.html*****************<html>
<script language="javascript" type="text/javascript">
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
ajaxRequest=new XMLHttpRequest();
}
else
{// code for IE6, IE5
ajaxREquest=new ActiveXObject("Microsoft.XMLHTTP");
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementbyID("product-A").innerHTML = ajaxRequest.responseText;
document.getElementbyID("product-B").innerHTML = ajaxRequest.responseText;
document.getElementbyID("product-C").innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "http://mywebsite/product-data.htm", true);
ajaxRequest.send(null);
}
</script>
<body>
<table>
<tr>
<td>Date</td><td>Product-A</td><td>Product-B</td><td>Product-C</td>
<tr>
<td><div id="today">Today</div></td>
<td><div id="product-A" onchange="ajaxfunction();">12</div></td>
<td><div id="product-B" onchange="ajaxfunction();">18</div></td>
<td><div id="product-C" onchange="ajaxfunction();">20</div></td>
</tr>
<tr>
<td>16/11/2010</td><td>1886</td><td>3888</td><td>3778</td>
</tr>
<tr>
<td>15/11/2010</td><td>2366</td><td>3888</td><td>4558</td>
</tr>
</body>
</html>
in myajax.html file at table row "Today" by AJAX with xmlhttp open from the URL file of
"http:www/mywebsite.com/ product-data.htm which is stored all product left for Today only
and is always changed depend on market need
I start to write myajax.html for Ajax update . And I found problem at
document.getElementbyID("product-A").innerHTML = ajaxRequest.responseText to grab
the data from product-data.htm , I mean I don't know to specifiy the location I need in
production-data.htm
Please advise to get update data for table (row2, col2), (row2, col3), row2, col4)
Below code is my ajax.html with the table and attached code is pruduct-data.htm
which is stored or saved all production data
I read the site, somepeoplesay it is better to use XML format instead of html for Ajax open URL and
some say it is better to use php to seach AJax data. So what is better, please also advise
Thanks a lot
Duncan
************myajax.html*****************<html>
<script language="javascript" type="text/javascript">
function ajaxFunction(){
var ajaxRequest; // The variable that makes Ajax possible!
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
ajaxRequest=new XMLHttpRequest();
}
else
{// code for IE6, IE5
ajaxREquest=new ActiveXObject("Microsoft.XMLHTTP");
}
// Create a function that will receive data sent from the server
ajaxRequest.onreadystatechange = function(){
if(ajaxRequest.readyState == 4){
document.getElementbyID("product-A").innerHTML = ajaxRequest.responseText;
document.getElementbyID("product-B").innerHTML = ajaxRequest.responseText;
document.getElementbyID("product-C").innerHTML = ajaxRequest.responseText;
}
}
ajaxRequest.open("GET", "http://mywebsite/product-data.htm", true);
ajaxRequest.send(null);
}
</script>
<body>
<table>
<tr>
<td>Date</td><td>Product-A</td><td>Product-B</td><td>Product-C</td>
<tr>
<td><div id="today">Today</div></td>
<td><div id="product-A" onchange="ajaxfunction();">12</div></td>
<td><div id="product-B" onchange="ajaxfunction();">18</div></td>
<td><div id="product-C" onchange="ajaxfunction();">20</div></td>
</tr>
<tr>
<td>16/11/2010</td><td>1886</td><td>3888</td><td>3778</td>
</tr>
<tr>
<td>15/11/2010</td><td>2366</td><td>3888</td><td>4558</td>
</tr>
</body>
</html>
Attachment:myajax.htmlproduct-data.htm