2016-04-03 37 views
0

Ajax çağrısı yapmak için sorun yaşıyorum. Javascript yöntemi del çağrılıyor, ancak ajax çağrısı oluyor.çerçeve oyna - ajax çağrısı

list.scala.html

@(products: List[Product]) 
@main("Products catalogue") { 
    <h2>All products</h2> 
    <script> 
    function del(urlToDelete) { 
     alert("In Ajax"); 
     $.ajax({ 
      url: urlToDelete, 
      type: 'DELETE', 
      success: function(results) { 
       // Refresh the page 
       //location.reload(); 
      }, 
      error : function(results) { 
       alert('Make call failed'); 
      } 
     }); 
     alert("End Ajax"); 
    } 
    </script> 
    <table class="table table-striped"> 
    <thead> 
     <tr> 
      <th>EAN</th> 
      <th>Name</th> 
      <th>Description</th> 
     </tr> 
    </thead> 
    <tbody> 
     @for(product <- products) { 
      <tr> 
       <td><a href="@routes.Products.details(product.ean)"> 
        @product.ean 
       </a></td> 
       <td><a href="@routes.Products.details(product.ean)"> 
        @product.name</a></td> 
       <td> 
       <ahref="@routes.Products.details(product.ean)">@product.name</i></a> 
       <button onclick="del('@routes.Products.delete(product.ean)')" >del</button> 
       </td> 
      </tr> 
     } 
    </tbody> 
    </table> 
} 

yolları

# Routes 
# This file defines all application routes (Higher priority routes first) 
# ~~~~ 

# An example controller showing a sample home page 
GET /       controllers.HomeController.index 
# An example controller showing how to use dependency injection 
GET  /count      controllers.CountController.count 
# An example controller showing how to write asynchronous code 
GET  /message     controllers.AsyncController.message 

# Map static resources from the /public folder to the /assets URL path 
GET  /assets/*file    controllers.Assets.versioned(path="/public", file: Asset) 

GET  /hello      controllers.HomeController.hello(name: String) 

GET  /products     controllers.Products.list() 
GET  /products/new    controllers.Products.newProduct() 
GET  /products/:ean    controllers.Products.details(ean: String) 
POST /products     controllers.Products.save() 

DELETE /products/:ean    controllers.Products.delete(ean: String) 

Kontrolör Products.java

public class Products extends Controller { 
... 
public Result delete(String ean) { 
    logger.info("delete product"); 
    final Product product = Product.findByEan(ean); 
    if(product == null) { 
     return notFound(String.format("Product %s does not exists.", ean)); 
    } 
    Product.remove(product); 
    return redirect(routes.Products.list()); 
} 
... 
} 
: İşte benim kodudur

Hata alıyorum ve tarayıcım hiçbir hata göstermiyor. javascript ilk uyarı ("Ajax"), ikinci uyarı ("End Ajax"), değil, denetleyici ("Products.java") oturum açma (konsol veya günlük dosyası) giriş değil, haşhaş olduğunu. Sanırım ajax çağrısı başlatılmadı, ama neyi kaçırdığımı bilmiyorum.

Zaman ayırdığınız ve yardım ettiğiniz için şimdiden teşekkür ederiz.

+0

Karşılık gelen girdileri 'route' dosyasından gönderin – Anton

+0

' route'larınızı gösterin –

+0

Bir hata iletisi alıyor musunuz? Geliştirici araçlarınızda tarayıcınızda neler oluyor? – Kris

cevap

0

Benim görüşüme göre ajax çağrınızı delete() yöntemiyle eşleştirmeniz gerekir. senin Ajax

$.ajax({ 
     url: /urlToDelete, 
     type: 'DELETE', 
     success: function(results) { 
      // Refresh the page 
      //location.reload(); 
     }, 
     error : function(results) { 
      alert('Make call failed'); 
     } 
    }); 

At Ve içinde Bunun gibi senin yolları

# Routes 
GET  /urlToDelete       controllers.Products.delete() 

Yani yöntem silmek() çağırarak olacaktır. Umarım bu size yardımcı olabilir.

İlgili konular