I am trying to make a shopping cart that updates using Ajax
And I am thinking that I should have a partial view with the shopping cart and then reload this partial view using Ajax to update the content of the cart. This seems like an elegant solution to the problem.
Is this the right approach, or is it better to do something else?
And if it is, can someone point me to an example of this? I am getting errors when calling f.x.:
Which is giving me "There is not current PublishedContentRequest, it must be initialized before the RenderRouteHandler executes". It gives the URL: /umbraco/RenderMvc/ShopCart
And different error when using different URLs. What is the correct url to use to get the partial view? It is located i n /Views/Partials/ShopCart.cshtml . Do I need other changes, like urlRewriting or creating a different controller?
If I use the URL "/Views/Partials/ShopCart" I get the error: "Cannot configure the request if there is not content assigned"
Refresh partial view with Ajax
I am trying to make a shopping cart that updates using Ajax
And I am thinking that I should have a partial view with the shopping cart and then reload this partial view using Ajax to update the content of the cart. This seems like an elegant solution to the problem.
Is this the right approach, or is it better to do something else?
And if it is, can someone point me to an example of this? I am getting errors when calling f.x.:
$.ajax({
url: '@Url.Action("ShopCart")',
type: 'GET',
cache: false,
success: function (data) {
alert(data);
}
});
Which is giving me "There is not current PublishedContentRequest, it must be initialized before the RenderRouteHandler executes". It gives the URL: /umbraco/RenderMvc/ShopCart
And different error when using different URLs. What is the correct url to use to get the partial view? It is located i n /Views/Partials/ShopCart.cshtml . Do I need other changes, like urlRewriting or creating a different controller?
If I use the URL "/Views/Partials/ShopCart" I get the error: "Cannot configure the request if there is not content assigned"
Any pointers are welcome - thanks :)
Hi Limberg,
The best way to do that, is create communication with server via JSON, and don't reload DOM elements with HTML.
But you have to write some code to bind your cart with server response )) Or Use something like Knockout )) but just for cart it's doesn't make sense.
THanks,
Alex
Ok, I was thinking of that as an option, but I thought the other solution with a partial view that is updated is cleaner
Why do you prefer doing this with JSON?
1. JSON is the smallest amount of data needed for communication server - web browser.
2. When you insert HTML in the page, DOM model is updated. With JSON you don't need that.
3. With JSON you have ready for USE js object and you can do anything with it.
THanks,
Alex
But if you do simple web site )) HTML is perfect ) fast and simple solution ))
is working on a reply...