PDA

View Full Version : Ajax Xhr ...



Grimsk
31 Jul 2007, 12:41 PM
i want to send my object to PHP and decode it with json ...

im not sure if i should use Ajax.request ..( cuz it doest work :"> )
"not a function"

should i use request with "prototype library" ,..?

anyone have a good example or any tips ..

Grimsk
31 Jul 2007, 1:06 PM
Ive got what im look for ..

var TreeHier = this.getTreeHier( this.TreePanel.getRootNode() );
var jsondata = Ext.util.JSON.encode(TreeHier);
console.log( TreeHier );
var conn = new Ext.data.Connection();
conn.request({
method: 'POST',
url: this.params.JSONAlbum,
params: { request: 'saveTree', treeNode: jsondata }
});

Thnks all :-)

BernardChhun
31 Jul 2007, 1:13 PM
hey Grismk,

here's my own XHR bridge function that may be hacked to use any adapter:


var function xhr(sUrl, params, successCB, failureCB, scope) {
if(!successCB){successCB = function(){};}
if(!failureCB){failureCB = function(){};}
if (!scope){scope = this;}
var callback = {success: successCB.createDelegate(scope), failure: failureCB.createDelegate(scope)};
/* replace that line below with the ajax code of your choice */
YAHOO.util.Connect.asyncRequest('POST', sUrl, callback, params);
}


here's how to use it :



var params = {"foo" : "bar"};
// Ext.urlEncode() will make the dictionnary look like this : foo=bar
xhr("foo", Ext.urlEncode(params)
, function(e){
// this is the success callback
var answer = eval("(" + e.responseText + ")");
/* do something useful when it is successful */
}
, function(e){
// this is the failure callback
var answer = eval("(" + e.responseText + ")");
// do something naughty when there's a failure
}
, this
);