Sono un po 'un newb con entrambi extJS e json. Qual è la via più indolore per inviare i dati JSON utilizzando extJS? Non mi interessa davvero nessuna caratteristica della GUI, ma semplicemente utilizzo il framework per inviare alcuni dati di esempio.Come inviare dati json con extJS
risposta
Ext.Ajax.request({
url: 'foo.php', // where you wanna post
success: passFn, // function called on success
failure: failFn,
params: { foo: 'bar' } // your json data
});
Gli esempi pubblicati qui mostrano l'idea di base. Per i dettagli completi su tutte le opzioni configurabili, vedere Ext.Ajax docs.
Il collegamento è interrotto, è necessario spostarsi sulla sezione EXT.Ajax – oden
Giusto per aggiungere i miei due centesimi:
//
//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;
Di seguito identificherà come richiesta '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
});
Di seguito vi identificano come 'GET' richiesta
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
});
è anche possibile utilizzare il metodo ': parametro POST '/' GET'': http://docs.sencha.com/extjs/4.1.3/#! /api/Ext.Ajax-property-method – efirat
Codice 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"
}
});
Oh, wow, che era molto più facile di quanto mi aspettassi. Grazie!!!!! – maximus
Questo invierà URLencoded come dati ... IOW, il buffer POST sarà foo = bar. Se si sostituisce 'params' per' jsonData', verrà inserito raw JSON, quindi il buffer POST sarà '{" foo ":" bar "}' – SBUJOLD
In ExtJS 4.1 è possibile utilizzare il membro jsonData. – Chris