通过AJAX删除项目后,页面向上滚动

Description : Hello I am developing Online food ordering site. I have almost completed the project but i am stuck at shopping cart..

Problem: I am facing problem when i delete the item from the cart which i have selected the page is scrolling up when i delete item from the cart.. I am using AJAX to add and delete items from the cart.

What will be the possible solution so that page do not scroll up when i delete the item from cart.??

You can check out here is the link : http://gogaily.com/restaurant_details.php?hotel_id=14 after page redirects click on MENU tab to view Menu items ... When u click on Menu items Cart will be displayed ,once u delete the item from cart Page scroll up.. How to avoid the page getting scrolled up.

That’s because you are using a link element with href="#" – the empty hash gets treated as “scroll to top” by browsers.

You simple have to suppress the “normal” link functionality after executing your JS code – keywords are event.preventDefault or return false (the latter for “traditional” event handling.

I think you have used anchor tag in delete button. ie.

<a href="#" ...>Delete</a> 

something like this. Do it with

<a href="">Delete</a> 

or use button i.e.

<button ...>Delete</button>

Hope you problem will be solved.

Replace href="#" with href="javascript:void();"