Site Navigation

May 5, 2008

Sending Test Params with Dojo

I wanted to send some test data to a server script from Dojo but I didn't want to create a form. After a little snooping around I found out the content property the xhr object will do this. However, I didn't find a lot of examples of how I was supposed to format the field. The documentation seems to indicate param=value, but that obviously wouldn't work. Below is an example of what works. Basic object literal format seems to do the trick. Just separate your name name:value pairs by commas and you should be good to go.
   1:      dojo.xhrPost(
   2:        {
   3:          url: 'ajax-student-test.php',
   4:          handleAs: "text",
   5:          timeout: 5000, // Time in milliseconds
   6:          content: { AppRequestType:"Initial Page Load" }, // Data to pass
   8:          load: studentHandler, //Called on a successful response.
   9:          error: ajaxErrorHandler,   // Called in an error case.
  10:        }
  11:      );
Post a Comment

Favorite Links Feed