javascript - PHP-Jquery-AJAX, show popup message -
I lost my way to finding a solution and need help immediately i have a php page called list.php which is Shows a list of products on each product with the purchased icon. After clicking the BUY button, it will direct action.php (which contains the script to add to the database) and then return to the same page using the header (location: list.php? Id = $ r [id_product]) will come. After coming back to the list, I want to show a popup message "The product has been added to the cart". How to do this?
You can do cookies
and check back only after returning If the cookie
is specified and if there is, show the message.
However, if you use AJAX
, you do not need cookies, just add pop-up functions in the AJAX parsing function, something like this
function addToBasket (itemId) {var x = new XMLHttpRequest (); X.open ('GET', '/ AJAX / activity.php? Add ='; Item ID is true); X.onreadystatechange = function () {if (x.readyState == 4) & amp; Amp; (X.status == "200") {var reaction obz = eval ('(' + x.responsetext + ')'); If (responseObj.status == 0) window.alert ('The product was successfully added to your basket'); And window.lart ('An error has occurred during the data process, please try again later'); }}; X.send (zero);
action.php
code example
& lt ;? Php // ... $ response = array ('condition' = & gt; 1); If (ISINIMRI ($ ITID) is), if (ISIIT ($ ITID) Put_in_table ($ item_id); $ response = array ('condition' =>);}} // output is an Ajax response header (' Content-type: application / javascript '); echo json_encode ($ response) ;? & gt;
Comments
Post a Comment