Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to post json data with extJS

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.

like image 947
maximus Avatar asked May 26 '10 23:05

maximus


4 Answers

Ext.Ajax.request({
   url: 'foo.php',    // where you wanna post
   success: passFn,   // function called on success
   failure: failFn,
   params: { foo: 'bar' }  // your json data
});
like image 73
Krishna K Avatar answered Nov 12 '22 04:11

Krishna K


The following will identify as 'POST' request

 Ext.Ajax.request({
       url: 'foo.php',    // where you wanna post
       success: passFn,   // function called on success
       failure: failFn,
       jsonData: { foo: 'bar' }  // your json data
    });

The following will identify as 'GET' request

Ext.Ajax.request({
   url: 'foo.php',    // where you wanna make the get request
   success: passFn,   // function called on success
   failure: failFn,
   params: { foo: 'bar' }  // your json data
});
like image 27
Sandeepan Kundu Avatar answered Nov 12 '22 05:11

Sandeepan Kundu


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;
like image 6
Ben Avatar answered Nov 12 '22 05:11

Ben


The examples posted here show the basic idea. For complete details on all configurable options see the Ext.Ajax docs.

like image 3
Brian Moeskau Avatar answered Nov 12 '22 04:11

Brian Moeskau