Developer forum

Forum » Templates » AJAX call to shop

AJAX call to shop

Martin Carlsen
Reply
Hi there,
I'm having problems with my jQuery AJAX call for my shop.

I've made a hidden page with a clean template - so it's a normal page with HTML.
When i try to run my AJAX it doesn't call the right page.

The AJAX page is called "AJAX.aspx" and the  testpage is "AJAXTest123.apx".
<script type="text/javascript">
function addToCart(productid)
{
	var url = "/AJAX.aspx?productid="+productid+"&cartcmd=add";
	$.ajax({
		type: "GET",
		url: url,
		dataType: "html",
		cache: false,
		success: function(data) {
			document.write(data);
		}
	});
}
addToCart('PROD420');
</script>
It keeps redirecting to the testpage (AJAXTest123) - and running and endless loop there.
How come?


Replies

 
Nicolai Høeg Pedersen
Reply
I think: When you add to cart, you write out all the response with document.write (line 11 in your example. That triggers the addToCart function to be run again, and again...). So remove that line or change it to alert();

 
Martin Carlsen
Reply
If i'm making it into an alert it just show me the content of AJAXTest123.aspx and not the AJAX.aspx-page.
 
Nicolai Høeg Pedersen
Reply
I need to have a URL to this page in order to see what is going on...
 
Martin Carlsen
Reply
This post has been marked as an answer
Edited: URL removed.

Found the solution by myself - added &redirect=/AJAX.aspx to the URL.
Votes for this answer: 0
 
Michael Nielsen
Reply
Otherwise use this excellent guide on how to create AJAX AddToCart functionality without wrinting custom code

http://websiteudvikler.dk/post/howto-implement-an-ajax-based-shopping-experience-in-dynamicweb-ecommerce.html

 

You must be logged in to post in the forum