views:

719

answers:

3

Greeings:

I'm a bit of a newb with both extJS and json. What is the most painless route to POSTing json data using extJS? I'm not really interested any GUI features, just using the framework to send some sample data.

+2  A: 
Ext.Ajax.request({
   url: 'foo.php',    // where you wanna post
   success: passFn,   // function called on success
   failure: failFn,
   params: { foo: 'bar' }  // your json data
});
Krishna K
Oh wow, that was a lot easier than I expected. Thanks!!!!!
maximus
This will post URLencoded like data... IOW, the POST buffer will be foo=bar. If you replace the `params` for `jsonData` it will post raw JSON, so the POST buffer will be `{"foo":"bar"}`
SBUJOLD
+1  A: 

You should probably read the Ext.Ajax docs.

bmoeskau
+1  A: 

Just to add my two cents:

//
//Encoding to JSON:
//
var myObj = {
  visit: "http://thecodeabode.blogspot.com/"
};
var jsonStr = Ext.encode(myObj);


//
// Decoding from JSON
//
var myObjCopy = Ext.decode(jsonStr);
document.location.href = myObj.visit;
Ben