Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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

Solution 2:

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
});

Solution 3:

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;

Solution 4:

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

Solution 5:

Code Snippet:

Ext.Ajax.request({
    url: "https://reqres.in/api/users",
    success: function (response) {
        Ext.Msg.alert("success", response.responseText);
    },
    failure: function () {
        Ext.Msg.alert("failure", "failed to load")
    },
    params: {
        "name": "morpheus",
        "job": "leader"
    }
});

Fiddle: https://fiddle.sencha.com/#view/editor&fiddle/28h1

Post a Comment for "How To Post Json Data With Extjs"