簡體   English   中英

我可以在scalatra中使用jquery ajax方法嗎? 如果沒有,我應該怎么用?

[英]Can I use jquery ajax method in scalatra? If not what should I use?

我可以在scalatra中使用jquery ajax方法嗎? 如果沒有,我應該怎么用?

我正在使用scalatra為Web項目制作骨架,而以下是我的js代碼,該代碼保持失敗。 請幫忙。

function addBook(){
    var addBookForm = $("#addBookForm").serialize();

    $.ajax({
        type: 'POST',
        url: '/booking/book',
        contentType: 'application/x-www-form-urlencoded; charset=utf-8',
        dataType: 'json',
        data: addBookForm,
        success: function(data){
            alert('SUCCESS')
        },
        error: function(e){
            alert('AJAX ERROR')
        }
    });
}

可以這樣解決

post("/book") {

    val result = mongoColl.find()
    val json = "[%s]".format(
      mongoColl.find().toList.mkString(",")
    )
    response.setContentType("application/json")
    Ok(json)
}

https://stackoverflow.com/a/12202410/4527543

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM