Jquery and play framework 2 javascript router issue -


i new javascript , trying implement ajax generation of html delete request play 2 framework server. in scala template have now. prints fields of model class item , need handle click @ a href using jquery.

how can fix code , pass appropriate item.id ajax request?

@(item: item)  <ul>   @for(field <- item.getclass().getfields()) {     <li>@field.getname() = @field.get(item)</li>   } </ul>  <a href="#" data-id="@item.id" id="delete">delete</a>       <script type="text/javascript">     $("#delete").click(function() {         var id = $(this).attr("data-id");         alert(id);         jsroutes.controllers.items.delete(id).ajax({});         return false;     });    </script> 

this link useful not give example of integrating jquery , javascript router in detail:

play 2.x: how make ajax request common button

you add id attribute on delete link:

<a href="#" data-id="@item.id">delete</a> 

and read jquery in js, like:

$('delete').click( function() {     var id = $(this).attr("data-id");     jsroutes.controllers.application.items.delete(id).ajax({     ... 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

c++ - Correct method for redrawing a layered window -

java.util.scanner - How to read and add only numbers to array from a text file -