# jQuery.post gets some code but the code isn't evaluated

**URL:** <https://discuss.rubyonrails.org/t/jquery-post-gets-some-code-but-the-code-isnt-evaluated/32568>\
**Category:** rubyonrails-talk\
**Created:** [July 30, 2008, 2:16pm UTC](https://discuss.rubyonrails.org/t/jquery-post-gets-some-code-but-the-code-isnt-evaluated/32568 "2008-07-30T14:16:37Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 30, 2008, 2:16pm UTC](https://discuss.rubyonrails.org/t/jquery-post-gets-some-code-but-the-code-isnt-evaluated/32568/1 "2008-07-30T14:16:37Z")

</div>

I'm calling one of my controller actions with this remote call:

jQuery.post("/plans/\<%= @plan.id %\>/add\_learning\_objective?name=" + objective\_name)

The action does its stuff and then falls through to a .js.rjs file that has this code:

page.alert("in rjs file") page.replace\_html "learning\_objectives", :partial =\> "test"

Then, nothing happens. In the firebug console, i can see that the result of the post call is this:

try {

alert("in rjs file");

jQuery("#learning\_objectives").html("NEW STUFF\n");

} catch (e) { alert('RJS error:\n\n' + e.toString()); alert('alert(\"in rjs file\");\njQuery(\"#learning\_objectives

\").html(\"NEW STUFF\\n\");'); throw e }

But, it looks like this code is being generated but not actually run: if i run the contents of the try block in the console then it does what it's supposed to do. Can anyone explain what's going on here?

thanks max

---

<div class="post-metadata">

**Author:** ![Rein\_Henrichs](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rein\_Henrichs](https://discuss.rubyonrails.org/u/Rein_Henrichs)\
**Post date:** [July 30, 2008, 5:45pm UTC](https://discuss.rubyonrails.org/t/jquery-post-gets-some-code-but-the-code-isnt-evaluated/32568/2 "2008-07-30T17:45:11Z")

</div>

> jQuery.post("/plans/\<%= @plan.id %\>/add\_learning\_objective?name=" + objective\_name)

You need to specify the type option as "script" to have it executed. (See the docs for jQuery.ajax(), where it is the dataType option. The "type" option in $.post is passed to $.ajax as the dataType option)

Rein

---

<div class="post-metadata">

**Author:** ![Rein\_Henrichs](https://avatars.discourse-cdn.com/v4/letter/r/71c47a/32.png) [@Rein\_Henrichs](https://discuss.rubyonrails.org/u/Rein_Henrichs)\
**Post date:** [July 30, 2008, 6:55pm UTC](https://discuss.rubyonrails.org/t/jquery-post-gets-some-code-but-the-code-isnt-evaluated/32568/3 "2008-07-30T18:55:23Z")

</div>

> jQuery.post("/plans/\<%= @plan.id %\>/add\_learning\_objective?name=" + objective\_name)

You need to specify the type option as "script" to have it executed. (See the docs for jQuery.ajax(), where it is the dataType option. The "type" option in $.post is passed to $.ajax as the dataType option)

Rein

---

<div class="post-metadata">

**Author:** ![11175](https://avatars.discourse-cdn.com/v4/letter/1/8edcca/32.png) [@11175](https://discuss.rubyonrails.org/u/11175)\
**Post date:** [July 31, 2008, 9:33am UTC](https://discuss.rubyonrails.org/t/jquery-post-gets-some-code-but-the-code-isnt-evaluated/32568/4 "2008-07-31T09:33:09Z")

</div>

Thanks Rein, that was exactly it: using .ajax instead of .post worked perfectly:

//doesn't evaluate the response, ie doesn't run the javascript in my .js.rjs file jQuery.post("/plans/\<%= @plan.id %\>/add\_learning\_objective?name=" + objective\_name);

//this works jQuery.ajax({ &nbsp;&nbsp;type: "POST", &nbsp;&nbsp;url: ("/plans/\<%= @plan.id %\>/add\_learning\_objective?name=" + objective\_name), &nbsp;&nbsp;dataType: "script" })

Thanks again max
