1

I have a gsp page index where I have a data table. On Click of the edit icon I want to redirect to edit view. I have tried some code over here but no result. It is redirecting to the index page itself. Can anyone please help me on this please? Here are my attempts below ::

    $('#example').on('click', 'a.edit-reference_1st', function (e) {
                var selectRow = $(this).parents('tr');
                var control = this;
                var referenceId = $(control).attr('referenceId');
//              alert(referenceId)
                window.location.href = '<g:createLink action="edit" id="${referenceId}" />'             
//              window.location.href="${createLink(controller: 'audio', action:'edit')}"+'/'+referenceId;
            });
MKB
  • 7,587
  • 9
  • 45
  • 71
Sumon Bappi
  • 1,937
  • 8
  • 38
  • 82
  • 1
    Try `window.location = "${g.createLink(controller: 'controllerName', action: 'edit')}/" + referenceId;` – MKB Jun 08 '15 at 11:48
  • @user1690588 thanks for your reply. Actually all the effort is working when I use this code `e.preventDefault();` without it nothing is working. thanks for your help. – Sumon Bappi Jun 09 '15 at 04:42
  • 1
    That's great. Make sure you test this in IE because you may got error in browser console and preventDefault may not works (Ref# http://stackoverflow.com/questions/1000597/event-preventdefault-function-not-working-in-ie. – MKB Jun 09 '15 at 04:47
  • 1
    In IE there's a lot of problem. I would like to leave IE – Sumon Bappi Jun 09 '15 at 05:09

1 Answers1

2

this happens in "client-land" (in your javascript in the browser). you have to generate the link on server beforehand (e.g. put it in a js var) and then build the link on the client side. pseudo code:

var baseLink = '<g:createLink action="edit" id="ID"/>';
$(..., function(e) {
    ...
    window.location.href = baseLink.replace("ID", referenceId);
}
cfrick
  • 35,203
  • 6
  • 56
  • 68
  • thanks for your reply,Now it is calling the controller method but after that loading the index page instead of edit – Sumon Bappi Jun 08 '15 at 11:20