Agile Web Development with Rails - Ajax

im using rails 2.3.3 and firefox web browser, i added ajax and java script and it works too, but i have to reload the page every time i click the add to cart button to show adding an item to the side of bar. it doesn't show it without rebooting.

anyone please help me how it can show adding an item in the sidebar when I click the add to cart button without reloading the page?

0


source to share


2 answers


If you haven't already, install Firebug for Firefox for the following reasons:

  • it will tell you if you have a Javascript error.
  • it will show you if your Ajax request and its content will be received.
  • you can check your page elements like the cart to see if it will render, if the id is correct, etc. much faster than viewing the source.
  • and much more (CSS, etc.).


If you can't figure it out by looking at the Firebug console, and since you've been following the tutorial, why don't you download the Depot source code and compare it to yours to see what you're doing wrong.

If you have a book, the full source will be listed at the end of the book. You can also download the source from here .

0


source


Standard accessories are methods ajax link_to_remote

, form_remote_tag

, form_remote_for

, button_for_remote

. (I may have missed a few.) If you are not using one of these, you might be doing something wrong.

If you are using one of the helper methods with remote

as part of the name, you may be missing an option, update

or the option update

is pointing to the wrong html element.

For a form_remote_tag

helper:



form_remote_tag(:url => {:controller => controller_name, :action => action_name, :id => id},
:update => element_to_update)

      

To_update_element must be the updated id of the html element.

0


source







All Articles