如何使用extJS发布json数据
答
Ext.Ajax.request({
url: 'foo.php', // where you wanna post
success: passFn, // function called on success
failure: failFn,
params: { foo: 'bar' } // your json data
});
答
这里发布的例子显示了基本思想。有关所有可配置选项的完整详细信息,请参见Ext.Ajax docs。
+0
链接已损坏,必须导航到EXT.Ajax部分 – oden 2014-07-14 05:36:09
答
我想补充我的两分钱:
//
//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;
答
下面将标识为“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
});
+1
您还可以使用'method:'POST'/'GET'参数:http://docs.sencha.com/extjs/4.1.3/#! /api/Ext.Ajax-property-method – efirat 2013-06-25 16:22:21
答
代码段:
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"
}
});
哇哦,那是比我预想的要容易得多。谢谢!!!!! – maximus 2010-05-27 04:56:30
这会发布URL编码的数据...... IOW,POST缓冲区将是foo = bar。如果你替换'jsonData'的'params',它会发布原始的JSON,所以POST缓冲区将会是'{“foo”:“bar”}' – SBUJOLD 2010-05-27 12:48:32
在ExtJS 4.1中,你可以使用jsonData成员。 – Chris 2012-07-03 13:11:02