small medium large xlarge

30 Sep 2010, 19:47
Scott Carleton (2 posts)

I’m new to Jquery and am attempting to use it within my depot application.
I have taken out prototype and replaced it with jquery-1.4.2 along with rails.js.

My line_items_controller.rb has the format.js line in it.

I am having difficulty with the first ajax call in Iteration F2. I am trying to convert the RJS template: create.js.rjs page.replace_html('cart', render(@cart))

with: create.js.erb

$("#cart").html("<%= escape_javascript(render :partial => "cart", :object => @cart) %>");

ajaxLinks is in my application.js:

function ajaxLinks(){

jQuery.fn.postWithAjax = function() {
  this.unbind('click', false); {
    $.post($(this).attr("href"), $(this).serialize(), null, "script");
    return false;
  return this;

It’s not rendering and I have no idea why. I think I’m headed in the right direction but am at a loss. Any help would be appreciated.


01 Oct 2010, 14:46
Scott Carleton (2 posts)

So I got it to work! Scratch everything above. Ryan Bate’s Railscast 136 was extremely helpful.

create.js.erb: $("#cart").html("<%= escape_javascript(render @cart) %>");


	'beforeSend': function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}

jQuery.fn.submitWithAjax = function() {
	this.submit(function() {
		$.post($(this).attr("action"), $(this).serialize(), null, "script");
		return false;  

$(document).ready(function() {
You must be logged in to comment