What I'm looking for looks like this in jQuery:
jQuery.ajaxSetup({
'beforeSend': function(xhr) {
xhr.setRequestHeader("Accept", "text/javascript");
}
});
...
$("#my_form").submit({
$.post($(this).attr("action", $(this).serialize(), null, "script");
return false;
});
Then, when my server returns some Javascript (the Accept-header bit), jQuery executes it (that last "script" parameter).
I'm trying to get the same effect in Dojo. My best guess is:
form = dojo.byId("my_form")
form.onsubmit = function() {
dojo.xhrGet({
url: form.action,
form: form,
handleAs: "javascript"
})
}
The handleAs: "javascript"
should cause Dojo to execute the response as JS. My problem is that I can't figure out how to set the header so that my web server (a respond_to do |format|
block in Rails) knows what to return.