简体   繁体   中英

Multiple execution of a pop-up made in php and jquery

I have a code to display a pop. The problem with this code is that it is executed several times if I want it to be executed only once. This pop-up is for the user to click on their country and change its currency. But when the pop-up comes up and we set the country, the page is refreshed again and the same pop-up appears. Do you have a solution to fix this problem? My code example:

    if(!isset($_COOKIE[$isfirstsee])) {
        global $WOOCS;
        $WOOCS->set_currency('GBP');
        $isfirstsee = "isfirstsee";
        $cookie_value = "no";
        setcookie($isfirstsee, $cookie_value, time() + (86400 * 30), "/"); // 86400 = 1 day
        //echo "tttt1";
        
        echo '<script>
                jQuery(function($){
                    $(".modal-dialog_swicher_shipping_parsa #billing_country").prepend($("<option>", {
                        value: 0,
                        text: "Choose the delivery location"
                    }));
                    $(".modal-dialog_swicher_shipping_parsa #billing_country  option[value=0]").attr(\'selected\',true);
                    $("a.shipToLink.clickaction").click();
                });
        </script>';
    }
    echo '<script>
            jQuery(function($){
                $(".modal-dialog_swicher_shipping_parsa #billing_country").prepend($("<option>", {
                        value: "all",
                        text: "All Countries"
                    }));
                $(".modal-dialog_swicher_shipping_parsa #billing_country").prepend($("<option>", {
                        value: "DE",
                        text: "Germany"
                    }));
                $(".modal-dialog_swicher_shipping_parsa #billing_country").prepend($("<option>", {
                        value: "NL",
                        text: "Netherlands"
                    }));
                $(".modal-dialog_swicher_shipping_parsa #billing_country").prepend($("<option>", {
                        value: "CA",
                        text: "Canada"
                    }));
                $(".modal-dialog_swicher_shipping_parsa #billing_country").prepend($("<option>", {
                        value: "GB",
                        text: "United Kingdom (UK)"
                    }));
                $(".modal-dialog_swicher_shipping_parsa #billing_country").prepend($("<option>", {
                        value: "US",
                        text: "United States (US)"
                    }));
                $(".modal-dialog_swicher_shipping_parsa #billing_country").prepend($("<option>", {
                        value: "my",
                        text: "My Top 5 Countries"
                    }));                
            });
    </script>';
    //global $WOOCS;
    //$WOOCS->set_currency('GBP');
    error_reporting(0);
}

Thanks

I also had this problem, the problem was from where I had a section to receive information inside the pop display form. This problem is due to the nature of the form and the POST method. Add the following code to the end of your jquery code. And be sure to let me know if the problem is solved or not. If my answer solves your problem. Good luck:)

<script>
if ( window.history.replaceState ) {
    window.history.replaceState( null, null, window.location.href );
}
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM