How do I execute JS XHR responses in Dojo?
What I'm looking for is similar to 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 (Accept-header bit) jQuery executes it (last script parameter).
I am trying to get the same effect in Dojo. My best guess:
form = dojo.byId("my_form")
form.onsubmit = function() {
dojo.xhrGet({
url: form.action,
form: form,
handleAs: "javascript"
})
}
handleAs: "javascript"
should call Dojo to execute the response as JS. My problem is that I can't figure out how to set up the header so that my web server (a block respond_to do |format|
in Rails) knows what to return.
+1
source to share