开发者

How to change the page url

开发者 https://www.devze.com 2023-03-28 13:40 出处:网络
I am building a shopping ca开发者_如何学运维rt using backbone.js . When some one clicks on \'add to cart\' I am making an ajax call using jQuery. Backend is rails. In response I get the new json value

I am building a shopping ca开发者_如何学运维rt using backbone.js . When some one clicks on 'add to cart' I am making an ajax call using jQuery. Backend is rails. In response I get the new json value for the cart. However if I display the cart view then car view comes up , however the url does not change.

To make the url change I after receiving the response from jQuery I need to do something so that router catches the new url and things proceed from there.

How do I navigate to the #cart url?


You can update the URL by calling the navigate method on your router, like this:

router.navigate('cart');


Most likely your view doesn't have access to the router you can do this:

Backbone.history.navigate('cart', {trigger:true});  // router handles view change


Backbone.history.navigate('cart');                  // only url is updated
0

精彩评论

暂无评论...
验证码 换一张
取 消