PDA

View Full Version : EditorGrid, XMl and posting changes via AJAX



rmorrissey
29 May 2007, 7:51 AM
Hey Guys,

I'm about to implement an EditableGrid for a project I'm working on. I have most of the code working now, and am about to send the results of edited cells to the server for integration with the existing DB backend.

I'm wondering whether anyone has any best practices for submitting large amounts of XMl via post?

At the moment I am using the following code to save/send:



eds = ds.getModifiedRecords();

for(var i = 0; i < eds.length; i++) {
var editXML = eds[i].store.reader.xmlData;
}

var cb = {success: function(o) { alert('success'); }, failure: function(o) { alert('failure'); } }
Ext.lib.Ajax.request('POST', '/ajaxhandler.php?command=setdata', cb, editXML);

ds.commitChanges();


Which gives me the following results from my (debug) PHP script:



Array
(
[<?xml_version] => "1.0" encoding="ISO-8859-1"?>
<plan>
<element>
<id>3629</id>
...
(the rest cut for space)

As you can see, it gets quite messy.

Before I go about doing some custom escaping - does anyone else have a 'best practice' solutions for this? Or have I missed something obvious you do in this situation?

tryanDLS
29 May 2007, 8:27 AM
Animal wrote a sample routine recently - search for asXml

rmorrissey
30 May 2007, 2:23 AM
Brilliant, thanks! Just what I needed.

Animal's post can be found here:

http://extjs.com/forum/showthread.php?t=6529&highlight=asXml

I think this would be really handy to have integrated fully. Maybe it would be more useful to have it called xmlToString, or somesuch though?

rmorrissey
30 May 2007, 5:14 AM
Just a note, I had to update the code that Animal provided very slightly in order to allow for ampersands within the data. As follows:



Ext.override(Ext.data.Record, {
asXml : function(rowIndex) {
var r = this.store.reader.meta;
var elName = r.record;
alert('elName: '+elName);
var result = "<" + elName + " id=\"" + this.id + "\">";

this.fields.each(function(f) {
alert('f.name: '+f.name);
result += "<" + f.name;

if (f.type && f.type !== "auto") {
alert('f.type: '+f.type);
alert('f.type - get: '+this.get(f.name));
result += " type=\"" + f.type + "\"";
}

result += ">" + window.escape(this.get(f.name)) + "</" + f.name + ">";
}, this);

return result + "</" + elName + ">";
}
});


Just in case anyone else needs it...

alucard001
13 Jun 2007, 9:12 PM
Hi there.

I am new to Ext, just saw your post and it is helpful to me.

However, I was stopped in the asXml part, like what you meet before.

I also saw the override "asXml" functions, but I don't know how to use this.

Can you give me your example on how to use this "asXml" thing?

Very thanks for your help.