I am unable to stop the previous variable loading during the ajax call.
我无法在ajax调用期间停止先前的变量加载。
Please find onclick I am passing the variable and sending the value to ajax call to PHP script.
请找到onclick我传递变量并将值发送到ajax调用PHP脚本。
I've got the data:
我有数据:
rnc.csv
DLRNC01
DLRNC02
DLRNC03
DLRNC04
DLRNC05
DLRNC06
DLRNC07
DLRNC08
DLRNC09
DLRNC10
DLRNC11
DLRNC12
DLRNC13
DLRNC14
code
<?php
if (($handle = fopen("rnc.csv", "r")) !== FALSE) {
$i=0;
$values=array();
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
?>
<a href="javascript:void(0)" onclick="pop(<?php echo "'".$data[0]."'"; ?>)" > <?php echo $data[0]; ?></a></br>
<?php
}
fclose($handle);
}
else{
echo "File not found";
}
?>
<div id="container1"></div>
<script>
//even I cleared the chache using the cache:false
//for every click different variable is passing to the ajax call and than to PHP script
function pop(rnc)
{
$.ajax({
url: 'ajax1.php',
type: "POST",
cache: false,
//dataType:'json',
data:{rnc:rnc},
success: function(data){
$("#container1").html(data);
setInterval(function(){
console.log(rnc);
$("#container1").html(data);
},2000);
}
});
}
</script>
ajax1.php
<?php echo $_POST['rnc']; ?>
When I am passing the value to the rnc_value.php, after clicking the values of the file two to more , than the ajax call is echoing what ever the values having previous called displaying for every 5 seconds.
当我将值传递给rnc_value.php时,在单击两个或更多文件的值之后,ajax调用将回显之前每5秒钟调用的值。
When I do console.log in the browser :
当我在浏览器中执行console.log时:
ajax.php:344 DLRNC01
ajax.php:344 DLRNC05
ajax.php:344 DLRNC07
ajax.php:344 DLRNC04
ajax.php:344 DLRNC01
ajax.php:344 DLRNC02
2 ajax.php:344 DLRNC05
ajax.php:344 DLRNC06
ajax.php:344 DLRNC07
ajax.php:344 DLRNC04
ajax.php:344 DLRNC01
ajax.php:344 DLRNC02
Please help me what is the solution..
请帮帮我解决方案..
1 个解决方案
#1
Alright, since our comments are going a little long, I'll move it to an answer box. So here is currently what you have...
好吧,既然我们的评论有点长,我会把它移到答案框。所以现在这里有你的...
function pop(rnc) {
$.ajax({
url: 'ajax1.php',
type: "POST",
cache: false,
data:{rnc:rnc},
success: function(data){
$("#container1").html(data);
setInterval(function() {
console.log(rnc);
$("#container1").html(data);
},2000);
}
});
}
What I'm suggesting is:
我的建议是:
//storage for the interval that will persist beyond the function call
var popInterval = null;
function pop(rnc) {
//if it is not the first invocation of pop, need to kill the previous interval
if (popInterval !== null) {
clearInterval(popInterval);
}
//start the new interval with the new 'rnc' data provided and store the interval reference
popInterval = setInterval(function() {
$.ajax({
url: 'ajax1.php',
type: "POST",
cache: false,
data:{rnc:rnc},
success: function(data){
console.log(rnc);
$("#container1").html(data);
}
});
},2000);
}
#1
Alright, since our comments are going a little long, I'll move it to an answer box. So here is currently what you have...
好吧,既然我们的评论有点长,我会把它移到答案框。所以现在这里有你的...
function pop(rnc) {
$.ajax({
url: 'ajax1.php',
type: "POST",
cache: false,
data:{rnc:rnc},
success: function(data){
$("#container1").html(data);
setInterval(function() {
console.log(rnc);
$("#container1").html(data);
},2000);
}
});
}
What I'm suggesting is:
我的建议是:
//storage for the interval that will persist beyond the function call
var popInterval = null;
function pop(rnc) {
//if it is not the first invocation of pop, need to kill the previous interval
if (popInterval !== null) {
clearInterval(popInterval);
}
//start the new interval with the new 'rnc' data provided and store the interval reference
popInterval = setInterval(function() {
$.ajax({
url: 'ajax1.php',
type: "POST",
cache: false,
data:{rnc:rnc},
success: function(data){
console.log(rnc);
$("#container1").html(data);
}
});
},2000);
}