如何使用extJS发布json数据

max*_*mus 19 html post json extjs

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

Kri*_*a K 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
});
Run Code Online (Sandbox Code Playgroud)

  • 这将发布URLencoded like data ... IOW,POST缓冲区将是foo = bar.如果替换``jmsData`的`params`,它将发布原始JSON,因此POST缓冲区将是`{"foo":"bar"}` (22认同)

小智 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
    });
Run Code Online (Sandbox Code Playgroud)

以下将标识为' 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
});
Run Code Online (Sandbox Code Playgroud)

  • 你也可以使用`method:'POST'/'GET'`参数:http://docs.sencha.com/extjs/4.1.3/#!/api/Ext.Ajax-property-method (2认同)

Ben*_*Ben 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;
Run Code Online (Sandbox Code Playgroud)