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

时间:2016-03-29 12:04:12

标签: jquery html jsp jstl

每次将一个元素放入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函数会出错,我无法从以前的问题中找到任何有用的东西来解决我的问题。

请有人可以提示如何这样做。

1 个答案:

答案 0 :(得分:0)

为什么不尝试使用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");

希望这有帮助。