Skip to content Skip to sidebar Skip to footer

How Do I Clear Previous Variable In Cache During The Ajax Call While Sending Variable To Php

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've got the

Solution 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...

functionpop(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 callvar popInterval = null;
functionpop(rnc) {
    //if it is not the first invocation of pop, need to kill the previous intervalif (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);
}

Post a Comment for "How Do I Clear Previous Variable In Cache During The Ajax Call While Sending Variable To Php"