Reputation: 477
I have an action in a controller
def deleteFiling={
obj.removeFiling()
redirect(action:"list")
}
that gets called form a gsp:
<g:link action="deleteFiling" id="${filingInstance.id}"> <img src="${resource(dir:'images',file:'trash.gif')}" title="Delete" />
and what it does it executes a DB query and then redirect to the main page with a success message.
So I need the gsp to call a different action that does some javascript work like a popup confirm message and once it's done it calls that action deleteFiling and execute it.
so I am doing something like this in extjs:
Ext.MessageBox.show({
title:'Commit Confirmation',
msg: 'You are about to <strong>Delete</strong> the entire <strong>Filing</strong>. This \n action cannot be reversed within the form PF application. \n\nAre you sure you want to Proceed',
buttons: Ext.MessageBox.YESNO,
fn: processDelete,
icon: Ext.MessageBox.QUESTION
});
function processDelete(btn, text){
$.ajax({
url : appContextRoot + '/filing/deleteFiling'
//success:mySuccessFunction
});
}
The problem that I am having is when I call the action through an ajax call, the query gets executed but the redirect DOES NOT
but when I call the action directly from gsp the redirect works. My question is what is the difference between calling an action using an ajax call from java script and calling it in directly from the gsp?
Upvotes: 0
Views: 3480
Reputation: 8587
I did a bit with java scripts in one one of my plugins. Have a look at this example:
There are plenty more examples in this folder you could adapt for your situation.. most of these execute and return remote result - which you could then vary according to output...
Upvotes: 0
Reputation: 1012
In Grails you can call action from JavaScript as following : userId and viewId are the parameter of action.
function closeAgentPopup(userId){
window.location.href="${createLink(action:'profile', controller:'agent')}"+'/'+userId+'?viewId=0';
}
Upvotes: 0
Reputation: 9365
In your GSP tag you don't call it with ajax. It's a direct GET request to your action. It means the whole page get refreshed. When you call your action with ajax the response of the action is rendered into an object. You can then show the result of the action (in your case a different action - the list action) by manipulating the DOM with Javascript.
You can, ofcourse, call the action with javascript without ajax:
function processDelete(btn, text){
loacation.href="${createLink(action: 'deleteFiling')}";
}
Upvotes: 1