我正在尝试从服务器加载一个带有 HTML 的新 jquery 选项卡:
$("#tab"+username).load("/lod1/ProfileServlet",{user:"username"},function(){
//fill in template with user's info
console.log("it worked");
});
服务小程序:
System.out.println("USERNAME HERE");
RequestDispatcher req = request.getRequestDispatcher("/WEB-INF/profileTemplate.html");
req.forward(request, response);
在浏览器中,我看到确认信息“成功了”,看来请求成功了。但是在服务器上我没有看到输出“USERNAME HERE”并且“#tabusername”没有填充请求的 html(我可以确认它在正确的位置):
<!DOCTYPE html>
<div>
<h1>USERS PROFILE AND THEME</h1>
</div>
最佳答案
由于您的 servlet 正在监听 GET,因此您不能将数据作为第二个数据参数传递给 .load()
。
使用它通过 GET 调用 servlet:
$("#tab"+username).load("/lod1/ProfileServlet?user="+username, function() {
//fill in template with user's info
console.log("it worked");
});
关于javascript - 使用 $().load() 从 Servlet 加载 html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53574926/