0

I am a little stumped as to why my Ajax call is failing, It was working and cannot think of any changes that would have affected it. When i make the call i get an error in firebugs console that points to this in my jquery.js file

// Do send the request
// This may raise an exception which is actually
// handled in jQuery.ajax (so no try/catch here)
xhr.send( ( s.hasContent && s.data ) || null );

Firstly what does this mean?

My setup is like so

index.js.erb

<% if params[:type] == 'Tynewydd' %>
 $('#newsResults').html('<%= escape_javascript(render partial: 'tynewyddposts') %>');
<% end %>

index.html.erb

 <div id="newsResults">
   <div class="hero-unit">
     <h2> Welcome to your admin area</h2>
       <p> xxxxxxxx.</p>
         <p>xxxxxxxxx</p>
   </div>
  </div>

Link for ajax request

<li><%= link_to 'Tynewydd', posts_path(:type => 'Tynewydd'), :remote => true %></li>

Can anyone see what is going wrong here please or offer some debugging suggestions?

Any help appreciated

Edit

Controller

def index
@posts = Post.all
@tynewyddpost = Post.tynewydd_posts
@woodsidepost = Post.woodside_posts
@elmspost = Post.elms_posts
@sandpiperpost = Post.sandpiper_posts
@outreachpost = Post.outreach_posts
@companypost = Post.company_posts
@staffpost = Post.staff_posts

respond_to do |format| 
 format.html 
 format.js 

end

Ok so i am no longer getting the error, i had an undefined method error for nil class in the called partial, so now in the console I can see the response but the partial that is supposed to render does not display on my page

Thanks

13
  • hey again, can you post your controller action? Commented Apr 5, 2013 at 23:01
  • Hi there :), just updated, im using scopes aswell in the post model Commented Apr 5, 2013 at 23:04
  • can you remove <% if params[:type] == 'Tynewydd' %> from the .js.erb file and say if it's working? Commented Apr 5, 2013 at 23:07
  • ok, for now don't put it back. Can you also put the _tynewyddposts.html.erb file? Commented Apr 5, 2013 at 23:09
  • im doing a <% @tynewyddpost.each do |t| %> or do you want the whole file? Commented Apr 5, 2013 at 23:11

1 Answer 1

1

ok so just in-case anyone else runs into a similar issue changing $ to jQuery has solved the problem, so this

<% if params[:type] == 'Tynewydd' %>
 $('#newsResults').html('<%= escape_javascript(render partial: 'tynewyddposts') %>');
<% end %>

was changed to this

<% if params[:type] == 'Tynewydd' %>
  jQuery('#newsResults').html('<%= escape_javascript(render partial: 'tynewyddposts') %>');
<% end %>
Sign up to request clarification or add additional context in comments.

5 Comments

are you using any other javascript frameworks/ libraries beside jQuery?
all jquery and using modernizer.js
it uses the dollar sign also somewhere? the reason i asked you: stackoverflow.com/questions/6746352/…
ah right it was because I am using jquery.noConflict() as there where conflicts with some plugins I am using..Understand now, thanks for finding that post
no problem, i heard about that problem i just didn't think of it :) Was trying to find a rails mistake. Good thinking!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.