Reputation: 1581
i am new to web programming so please excuse my naive question, i tried searching on web but couldn't find answer to my basic question.
I am using extjs (for widgets and ajax) and python (using bottle) on server side.
here is my requirement.
I have extjs EditorGrid which has just one column (editable). on the index route (bottle route) i return json dictionary which is populated in this grid and shown, all well till this point, now I want to update value of this column and save updated value on the server side.
so i added another route on my python script, and ajax_reply as url to my ajax request on javascript (code below).
now my question is that how do i send a response to client, say for example i want to send a failure to client (i.e. updated was not successful on server and i want to send ajax response that update failed. i tried sending random stuff from my ajax_reply route but always success is called on client.
I am confused how to send a json response from ajax_repose function and then parse it again in my javascript success or failure function to act accordingly.
any help is much appriciated
@bottle.route('/ajax_reply', method='POST')
def update_column():
return { 'success' : False }
var grid = new Ext.grid.EditorGridPanel({
tbar: [{ text : 'Remove' }, {text : 'Add'}],
ds: ds,
frame:true,
listeners: {
afteredit : function(e){
Ext.Ajax.request({
url : '/ajax_reply',
params : {
action: 'update',
id : e.record.id,
field: e.field,
value : e.value
},
success : function(resp, opt){
e.record.commit();
Ext.Msg.alert('SUCCESS', 'success...');
},
failure: function(resp, opt){
Ext.Msg.alert('ERROR', 'error...');
e.record.reject();
}
});
}
},
Upvotes: 0
Views: 1043
Reputation: 17860
If you're using Ext.Ajax.request
you need to parse response yourself. Even if server can't update record but generated some kind of proper response
{ success: false, msg: 'Failed to save record' }
success
function. Because Ajax request itself was successful. However if you're using grid and editors - I would recommend to look at different way of doing this - check documentation for remote stores, readers/writers etc.
Upvotes: 1