如何使用extJS发布json数据

时间:2010-05-26 23:36:03

标签: html json post extjs

我对extJS和json都有点新意。使用extJS发布json数据最无痛的路径是什么?我并不真正对任何GUI功能感兴趣,只是使用框架发送一些示例数据。

5 个答案:

答案 0 :(得分:24)

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

答案 1 :(得分:20)

以下内容将标识为“ POST ”请求

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

以下内容将标识为“ GET ”请求

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

答案 2 :(得分:6)

加上我的两分钱:

//
//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;

答案 3 :(得分:3)

此处发布的示例显示了基本概念。有关所有可配置选项的完整详细信息,请参阅Ext.Ajax docs

答案 4 :(得分:0)

代码段:

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

小提琴:https://fiddle.sencha.com/#view/editor&fiddle/28h1