Html 如何使用extJS发布json数据

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2917581/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:12:43  来源:igfitidea点击:

How to post json data with extJS

htmljsonpostextjs

提问by maximus

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.

我是 extJS 和 json 的新手。使用 extJS 发布 json 数据的最轻松的途径是什么?我对任何 GUI 功能都不感兴趣,只是使用框架发送一些示例数据。

回答by Krishna K

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

回答by Sandeepan Kundu

The following will identify as 'POST' request

以下将识别为“ 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
    });

The following will identify as 'GET' request

以下将识别为“ 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
});

回答by Ben

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;

回答by Brian Moeskau

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

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

回答by Saurabh Nemade

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

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