PDA

View Full Version : RenderText/JsonConvert



anitacynax
1 Jul 2012, 11:43 PM
I have a DeleteUser function that gets called when the user clicks on the delete row icon in an actioncolumn.
Here is the code for the function:


function DeleteUser(id) {
Ext.Ajax.request ({
url: 'user/delete/castle',
params: {id: id},
success: function (result, request) {
Ext.MessageBox.alert('Success', result.responseText);
},
failure: function (result, request) {
alert (result.responseText);
}
});
}


Right now, when a user is deleted, a pop-up appears with the title "Success" but the result.responseText parameter is empty.
I need the result.responseText parameter to be "User deleted successfully" but I need to pass that by using RenderText (JsonConvert) in the delete function that gets called via the url.
Here is the code for that delete function:



public void Delete (int id) {
CancelView();
CancelLayout();
User user = User.FindUser(id);
user.Delete();
RenderText(JsonConvert.SerializeObject(???);
}

Does anyone have any tips as to how to do this? I am new to Ajax requests and JSON.

Thanks for the help.

sword-it
2 Jul 2012, 12:29 AM
Hi!

You must modify your success and failure functions to decode data
Like below:-




, success: function (data) {
var data = Ext.util.JSON.decode(data.responseText);
if (data.Root.ReturnCode == 0) {
this.onSuccess(data.Root.DisplayMessage);
}
else {
this.onFailure(data.Root.DisplayMessage);
}
}

anitacynax
2 Jul 2012, 12:39 AM
Thanks for your prompt reply, sword-IT. My assignment, however, is to leave the code of the DeleteUser function unaltered and use RenderText (in the delete function) to get result.responseText to equal "User deleted successfully". Any tips on how to do this?

anitacynax
22 Jul 2012, 11:10 PM
Thanks everyone for your input. This question was perfectly answered here: http://stackoverflow.com/questions/11289915/rendertext-jsonconvert