I have some products that are in my SQL database whose links with $ producturl be retrieved in my script These URLs are actually adding products to the cart (). I am trying to create a script that will allow the user to add products to the car but will not redirect them, just execute the link so that the user can remain on the same page.
I am using preventDefault and stopPropgation but it is not working, it seems alert, but when I look at my cart, then it is not executing the link after which the product is not . Any help?
& lt ;? Php $ producturl = ProductURL :: find (array ('product' = & gt; $ tube1- & gt; tube1)); If ($ product calls [0] - & gt; url! = Null) {echo '& lt; Span id = "shop" & gt; Add Cart NoRedirect & lt; / Span & gt; '; }? & Gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .on ('click', '#shop', function (event) {$ .post ('& lt ;? php echo $ producturl [0] - & gt; URL;; & gt;'); Event.preventDefault (); Event.stopPropagation (); Warning ('Product added to cart);}); & Lt; / Script & gt;
Your HTML anchor link:
& lt ; A href = "http://www.google.com" & gt; Link & lt; / A & gt;
Do not forget to put jQuery inside it (inside a dummy function):
// Act on an element $ click ("A") . ('Click', function (e) {// stop default action, in this case a link e.preventDefault (); // catching an attribute of the href attribute var url = $ (this) .attr ('href' ); // Get a request to use AJAX for ARF value $ $ .get (href, function () {// success});
This indicates all the principles required to implement your function.
The page provided in the question and the URL posted on the same subdomain, or cross-open REAS resource must be enabled on the server otherwise the request will fail due to cross domain restrictions.
No comments:
Post a Comment