I am unable to stop the previous variable loading during the ajax call.
Please find onclick I am passing the variable and sending the value to ajax call to PHP script.
I having 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>
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);
},5000);
}
});
}
</script>
ajax1.php
<?php echo $_POST['rnc']; ?>
when I am passing the value to the ajax1.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.
When I do console.log in the browser :
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
clicking the particular value, calling the previous value in the second time...
Please help me what is the solution..