在 jquery drop 函数中编写一个 jstl sql 查询?

Write a jstl sql query inside a jquery drop function?

每次将元素放入 droppable 中时,我都想访问数据库并输出我从其 id 中获得的内容。

 drop: function(event,ui){
     $(ui.draggable).detach().css({top:0,left:0}).appendTo($(this)); 
     $(ui.draggable).detach().css({top:0,left:0}).appendTo($(this));
     var slotid=$(this).attr("id");
     var courseid=$(ui.draggable).attr("id");
     //Using the above two variables I want to get(and also change) something from(in) the database
 }

但是在这里插入 jstl 函数会出错,我无法从以前的此类问题中找到任何有用的信息来解决我的问题。

有人能给点提示吗?

你为什么不试试 ajax?哪个更适合您的查询。

drop: function (event, ui) {                                      
    $.ajax({
        type: "POST",
        data: { slotid: $(this).attr("id"), courseid: $(ui.draggable).attr("id");},
        url: 'ServletURL',
        success: function (data) {
            alert(data);
        }
    });
}

您需要做的就是使用以下参数创建单独的函数来查询数据库,

String slotid = request.getParameter("slotid");
String courseid = request.getParameter("courseid");

希望对您有所帮助。