PDA

View Full Version : Harnessing a POST's response



UGA_Zimma
19 Aug 2009, 12:43 PM
Is there any way to access the JSON response from a POST/submit() function.

Example: My button submits/POSTs a form and I want a store to load itself with the JSON response from the server sends.

My tomcat shows my JSON response coming back fine I just cant figure out how to load the store with the response.

Thanks in advance for any help,

UGA_Zimma

avsomeren
19 Aug 2009, 12:53 PM
frm.submit({
method: 'POST',
url: ###YourUrl###,
waitTitle: 'Connecting...',
waitMsg: 'Saving data...',
scope: this,
success: function(form, action)
{
if (action.result.success == true)
{
}
}
});


The result of your form post is found in action.result . The json format i use is listed below. you could easily put a list of records in the records variable within the json string.



{"success":true,"error":null,"RecordCount":0,"Records":null}

UGA_Zimma
19 Aug 2009, 1:10 PM
Thanks for the reply, that helps!

Now i want to somehow load a store using the action.result object (which is JSON formed like {"success":true, "data":[...]}, I tried this with no luck:



success: function (form, action){
testStore.load(action.result);
}


Thanks for the help in advanced,

UGA_Zimma

avsomeren
19 Aug 2009, 1:30 PM
Didnt have the chance to test this but it might be worth a shot...



teststore = new Ext.data.JsonStore({
root: 'records',
idProperty: 'id',
fields: ['id', 'name', 'url', {name:'size', type: 'float'}, {name:'lastmod', type:'date'}],
data:action.result
});
teststore.load();

UGA_Zimma
19 Aug 2009, 2:03 PM
Thanks Again For The Posts, i figured it out:

testStore.loadData(action.result)

Thanks for the help!

UGA_Zimma