Reputation:
I can add a product to cart via GET with this link:
<div id="add"><a id="add-link" href="http://localhost/catalog/cart?product_id=8&boutique_id[]=36&func=Module::Cart->add">Add to Cart</a></div>
I want to use jQuery Ajax to stay on the same page (if JS is enabled). I have crapped out the following, but of course it does not work. Could someone please look what is wrong? Thanks.
<script type="text/javascript">
$(document).ready(function(){
$('a#add-link').bind("click", function(event) {
event.preventDefault();
var url = $(this).attr("href");
alert("Now I want to call this page: " + url);
$.ajax({
type: "GET",
url: "url="+url,
success: function() {
alert("Product added to cart");
}
});
});
});
</script>
Upvotes: 3
Views: 12580
Reputation: 93
$(document).ready(function(){
$('a#add-link').bind("click", function(event) {
event.preventDefault();
$.get($(this).attr('href'), function(data, status) {
alert("Product added to cart");
});
});
Upvotes: 1
Reputation: 2903
Take out that "url="+
Also, url might not be the best variable name.
Upvotes: 0
Reputation: 30103
var url = $(this).attr("href"); alert("Now I want to call this page: " + url); $.get(url, function (resp) { alert("Product added to cart"); });
Upvotes: 7