Reputation: 15384
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
Upvotes: 0
Views: 1019
Reputation: 15384
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 %>
Upvotes: 1