Milople Inc
Milople Inc

Reputation: 399

Using jquery-ajax with play 2.0 framework

I have a problem where in i have to fetch the particular data of row on clicking that particular rows button and have to display that data via ajax on the same page.

Here is the code of index.scala.html:

@(products: List[Products])

@import helper._
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<h1>@products.size() product(s)</h1>
<table border=1>
<tr>
<td>Product Name</td>
<td>Quantity</td>
<td>Price</td>
</tr>
@for(product <- products) {
    <tr>
        <td>
            @product.productname
        </td>
        <td>
            @product.quantity
        </td>
        <td>        
            @product.price
        </td>
        <td>        

            <input type="button" value="Add Product" name="@routes.Application.user(@product.product_id)" id="but"/>

        </td>
    </tr>
}
</table>


<div class="result" style="border: 1px solid black; padding: 5px;">not sent yet...</div>


<script type="text/javascript">
    jQuery("#but").click(
            function () {
                $.get(jQuery(this).attr("name"), function (data) {
                    $('.result').html(data);
                });
                return false;
            }
    )
</script>

My Application.java contains the method as shown below:

public static Result user( id){
        return ok("Play's controller told that you're about to get data for user no. "+id);
    }

The problem i am facing is in the line:

        **<input type="button" value="Add Product" name="@routes.Application.user(@product.product_id)" id="but"/>**

Error is: Compilation error illegal start of simple expression

Can anyone please help to load the dymanic data.

Upvotes: 1

Views: 545

Answers (1)

ndeverge
ndeverge

Reputation: 21564

Please remove the second @:

@routes.Application.user(product.product_id)

The second one is not needed, since the first indicates that you're in the templating language.

Upvotes: 2

Related Questions