0

I would like to pass the value of the variable orderSlipID to this createLink.

function showOrderedItems() {       
    $.ajax({
        url: '${createLink(action:'listOrderedMenu', id:orderSlipID)}', 
        success: function(data) {
          $('#orderedlist').html(data);                                                     
        }
    });
};      

this orderSlipID comes from a seperate GSP. I would like to set the id of the createLink to the id of the button that I click.

Here's my other GSP:

<g:each  in="${orderSlipInstanceList}" var="os">
    <div class="table" data-slip="${os.id}">${os.tableNumber}</div>
</g:each>
<script>
    $('.table').click(function(){
    orderSlipID = parseInt($(this).attr('data-slip'));
    showOrderedItems(); 
 });
</script>

So when I click a table it will save the id of the orderedSlip to orderSlipID and pass it to createLink to display the new content of #orderedlist.

3
  • orderSlipID is coming from where? Server or client? If client, impossible since the server code does not run at that point in time. Can't you just send up the data in the GET data like you would for any other GET request? Commented Mar 14, 2014 at 17:29
  • And as I was saying, You need to pass up the id with data in the Ajax request. Commented Mar 14, 2014 at 18:10
  • Another post about the same subject : stackoverflow.com/questions/22044925/… Commented Mar 14, 2014 at 18:42

2 Answers 2

1

Just pass the orderSlipID in the jQuery method as an argument

<script>
    $('.table').click(function(){
        var orderSlipID = parseInt($(this).attr('data-slip'));
        showOrderedItems(orderSlipID);
    });
</script>

and change in ajax

function showOrderedItems(orderSlipID) {
    $.ajax({
        url: '${createLink(action:'listOrderedMenu')}', 
        data: {id: orderSlipID},
        success: function(data) {
            $('#orderedlist').html(data);                                                     
        }
    });
};  
Sign up to request clarification or add additional context in comments.

Comments

0

Nevermind, I have solved the problem by assigning a url for each button

     <g:each  in="${orderSlipInstanceList}" var="os">
       <div class="table" data-url="${createLink(action: 'listOrderedMenu', id:"${os.id}")}">${os.tableNumber}</div>
     </g:each>

and by using a url variable:

  var urlSlip = '${createLink(action:'listOrderedMenu', id:11)}';

and changed the $.ajax url to

  url:urlSlip

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.