Update only values from an <col>
So I really need to know if it's possible to update the values under a specific column on a table.
<table>
<col with="auto">
<col with="auto">
<col with="auto" id="update_me">
<?php
for(hundreds of lines){
?>
<tr>
<td>something 0</td>
<td>somet开发者_如何学Pythonhing 1</td>
<td>Need to update</td>
<tr>
<?php
}
?>
I will be using:
<script>
$(document).ready(function() {
$("#update_me").load("response.php");
var refreshId = setInterval(function() {
$("#update_me").load('response.php');
}, 6000);
$.ajaxSetup({ cache: false });
});
</script>
The php will only generate the values from the specific column!
I think this is more what you are looking for:
My Table
<table>
<tr>
<td width="auto"> </td>
<td width="auto"> </td>
<td width="auto" id="update_me1"></td>
<tr>
<tr>
<td width="auto"> </td>
<td width="auto"> </td>
<td width="auto" id="update_me2"></td>
<tr>
<tr>
<td width="auto"> </td>
<td width="auto"> </td>
<td width="auto" id="update_me3"></td>
<tr>
</table>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$("#update_me").load("response.php");
var arr = ['1','2','3'];
var refreshId = setInterval(function() {
$.each(arr, function() {
$('#update_me' + this).load('response.php');
});
}, 6000);
$.ajaxSetup({ cache: false });
});
</script>
UPDATE: This javascript calls the response.php multiple times. So for each ID in arr
it will call the script. If you pass the ID to the script (as described in my comments below), you can limit the data returned by each request:
$('#update_me' + this).load('response.php?id' + this);
This means that for each iteration of arr
, you will be calling response with the appropriate id:
'#update_me1' is populated with the results from 'response.php?id=1'
'#update_me2' is populated with the results from 'response.php?id=2'
'#update_me3' is populated with the results from 'response.php?id=3'
etc...
Otherwise, you need to call response.php once and parse the data in the javascript. Those are the only options you have.
I don't understand why nobody has suggested
jQuery("td:nth-child(" + column_number + ")").each(function(row_number)
{
//Do something to this row's cell in column "column_number"
});
<script>
$(document).ready(function() {
var refreshId = setInterval(function() {
$.getJSON('response.php', function(data) {
$.each(data, function(index, value) {
$('#value'+index).html(value).show();
});
});
}, 3000);
$.ajaxSetup({ cache: false});
});
</script>
精彩评论