imjp
imjp

Reputation: 6695

Problem with adding ajax to my app

Hey guys I'm currently going through the Agile Web Development 4th Edition eBook and I'm currently stuck in a chapter where they added some ajax but it's not working for me.

Chapter 11.2(for those that also have the ebook)

I have a shopping cart in the sidebar of my homepage which needs to be updated via AJAX with the following code in app/views/line_items/create.js.erb which is called once the create action is called

page.replace_html('cart', render(@cart))

In the line_items controller it's just set at format.js if the create action is called successfully.

Right now page is not refreshing but the content is being added via ajax. In order to see the updated shopping cart I need to update the entire page, which is not the idea.

I'm thinking that the create.js.erb code is not correct because everything else is working like it's supposed to except that snippet :|

Here's my github page: https://github.com/imjp/shop I hope you guys can help me out :)

Upvotes: 1

Views: 64

Answers (2)

imjp
imjp

Reputation: 6695

The code wasn't working because it is scriptaculous syntax... I've used the jQuery version of the code and it works just fien :)

Upvotes: 0

jvnill
jvnill

Reputation: 29599

I think the problem here is that you don't have a format.js line in your respond_to block. So when an ajax request is made, the default response of the server goes to whatever format.html does.

Upvotes: 1

Related Questions