Saturday 15 June 2013

javascript - Rails + AJAX is returning more HTML than expected -



javascript - Rails + AJAX is returning more HTML than expected -

i'm new rails , appreciate insight! updating rails' or ruby's version not option, beingness required utilize client's current version.

ruby version: 1.9.3-p194, rails version: 3.2.18

i'm loading in dynamic html content through javascript/jquery ajax call. works fine when create ajax phone call within of app/assets/javascripts/application.js. here's call:

$.ajax({ url: '/search/login', cache: true, success: function(html){ console.log('success: ', html); } });

the response variable called html contains html within of /search/login.html.erb

however, if move exact phone call javascript file such app/assets/javascripts/search/jh.js, seems work fine except html that's returned lot more expected. contains entire html dom tree, <doctype> </html> in add-on content /search/login.html.erb.

can please help me understand why happening?

you need specify not want render layout type of ajax phone call otherwise rails treat standard view request inclusive of application or template layout. need add together next render action in controller

render layout: false

this tell rails process html.erb file without application layout or other template specified controller.

javascript jquery ruby-on-rails ruby ajax

No comments:

Post a Comment