# Sinatra: jquery displays ruby code when calling for an update. a little help please

**URL:** <https://www.ruby-forum.com/t/sinatra-jquery-displays-ruby-code-when-calling-for-an-update-a-little-help-please/174713>\
**Category:** Rails\
**Created:** [August 31, 2009, 8:18pm UTC](https://www.ruby-forum.com/t/sinatra-jquery-displays-ruby-code-when-calling-for-an-update-a-little-help-please/174713 "2009-08-31T20:18:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/da6949/32.png) [@Kreas](https://www.ruby-forum.com/u/Kreas)\
**Post date:** [August 31, 2009, 8:18pm UTC](https://www.ruby-forum.com/t/sinatra-jquery-displays-ruby-code-when-calling-for-an-update-a-little-help-please/174713/1 "2009-08-31T20:18:43Z")

</div>

Hey all,

So I’m running into an issue with jquery when making an ajax call to  
retrieve a string. It comes back displaying the entire chunk of code  
rather than rendering it in my erb file… I’m confused.

Here’s the actual code hopefully someone can help before I pull my  
hair out.

----results.js—  
$(function() {  
$(".search\_box").live(“keyup”, function() {  
$.getScript("/javascripts/index.js.erb");  
return false;  
});  
});

— index.js.erb —  
$("#jresults").html(’\<%= escape\_javascript(erb(:results, :layout =\>  
false)) %\>’);

This works for the most part but the \<%= escape\_javascript(erb  
(:results, :layout =\> false)) %\> actually displays in my view when I  
call for the update. Looking at the source it looks like the original  
data is there also.

Has anyone ran into this before? I’m sure it’s a big red truck but  
right I can’t figure it out for the life of me.

OH and before I forget I’m using Sinatra for this app.

---

<div class="post-metadata">

**Author:** ![Kreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/da6949/32.png) [@Kreas](https://www.ruby-forum.com/u/Kreas)\
**Post date:** [August 31, 2009, 8:22pm UTC](https://www.ruby-forum.com/t/sinatra-jquery-displays-ruby-code-when-calling-for-an-update-a-little-help-please/174713/2 "2009-08-31T20:22:49Z")

</div>

On Aug 31, 6:54 pm, Kreas [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Hey all,
> 
> So I’m running into an issue with jquery when making an ajax call to  
> retrieve a string. It comes back displaying the entire chunk of code  
> rather than rendering it in my erb file… I’m confused.

> Here’s the actual code hopefully someone can help before I pull my  
> hair out.

You omitted the most relevant of code: the ruby code processing the  
request. Given that rails is not involved at all, the sinatra google  
group may be more relevant.

Fred

---

<div class="post-metadata">

**Author:** ![Kreas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/da6949/32.png) [@Kreas](https://www.ruby-forum.com/u/Kreas)\
**Post date:** [September 1, 2009, 11:22pm UTC](https://www.ruby-forum.com/t/sinatra-jquery-displays-ruby-code-when-calling-for-an-update-a-little-help-please/174713/3 "2009-09-01T23:22:58Z")

</div>

You have a good point on the group. 🙂

On Aug 31, 1:20 pm, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
