views:

675

answers:

3

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.

A: 

Not sure about dojo myself but I do know that phiggins (lead dojo dev) is available on the #dojo channel over on freenode irc, that is if nobody else can give you an answer.

redsquare
+2  A: 

I believe the answer is:

form = dojo.byId("my_form")
  form.onsubmit = function() {
  dojo.xhrGet({
    url: form.action,
    form: form,
    handleAs: "javascript",
    headers: { "Accept": "text/javascript" }
  })
}
James A. Rosen
A: 

I have a question? that i am new to dojo and i want to use dojo but found a problem if any one help me how to run and program the dojo? thanx awnser me or send me dojo toturial [email protected]

Scorpians
There's this button up and right on the page which says "Ask Question". Press it.
Jani Hartikainen