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

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

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

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

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({   type: "POST",   url: ("/plans/<%= @plan.id %>/add_learning_objective?name=" + objective_name),   dataType: "script" })

Thanks again max