PDA

View Full Version : How do I send RAW POST DATA via the XML Data Model?



steve.neill
30 Nov 2006, 8:45 AM
I'm not sure if the subject line makes sense, but what I'm trying to do is implement a paged data grid. Requests to the server will be made using small XML documents that contain filter/sort/paging info.

What is the best way to send this data to the server? Do I need to override methods in the LoadableDataModel or XMLDataModel? I guess what needs to happen is that I specify some postdata, but also send custom headers (Content-Type and Content-Length) such that the server script (PHP in this case) gets the $HTTP_RAW_POST_DATA variable populated with my XML.

Can you please suggest the best way to approach this.

Thanks for all the great work!

Steve Neill

jbowman
30 Nov 2006, 9:13 AM
check this thread out, for how to add more POST variables to the datamodel to pass to your backend

http://www.yui-ext.com/forum/viewtopic.php?t=715&highlight=filter

steve.neill
30 Nov 2006, 9:29 AM
Thanks for the reply. However, this isn't quite what I need. The problem is that the server is not checking $_POST, but $HTTP_RAW_POST_DATA. The client therefore needs to send POST data as Content-Type: application/xml with Content-Length set to the length of the post data. Is this possible?

Thanks,

Steve

tryanDLS
30 Nov 2006, 9:48 AM
You can probably do that by modifying the underlying request to YAHOO.util.Connect.asyncRequest. Look at the YAHOO.util.Connect.initHeader method. You might have to override the yui-ext method that calls the YAHOO method, if it currently doesn't expose access to the request object before firing if off.

steve.neill
30 Nov 2006, 3:50 PM
For anyone else who's interested... I got it working by overriding the data model "load" method:

Steve



// override default 'load' method
dm.load = function(url, params, callback, insertIndex) {
this.fireEvent('beforeLoad', this);

var postdata = "foo";
var cb = {
success: this.processResponse,
failure: this.processException,
scope: this,
argument: { callback: callback, insertIndex: insertIndex }
};

YAHOO.util.Connect.setDefaultPostHeader(false);
YAHOO.util.Connect.initHeader('Content-Type', 'application/xml');
YAHOO.util.Connect.initHeader('Content-Length', postdata.length);
YAHOO.util.Connect.asyncRequest('POST', url, cb, postdata);
};