我需要在我的js文件中获取获取路径。我使用nodejs并在服务器端进行表达。我需要获取请求的路线app.get('/ book',function(){});如何使关闭引导模式的http获取请求
$('#myModal').on('hidden.bs.modal', function(){
// note sure what to fill in here
});
我需要在我的js文件中获取获取路径。我使用nodejs并在服务器端进行表达。我需要获取请求的路线app.get('/ book',function(){});如何使关闭引导模式的http获取请求
$('#myModal').on('hidden.bs.modal', function(){
// note sure what to fill in here
});
使用jQuery的内置get方法:
$('#myModal').on('hidden.bs.modal', function(){
$.get("/books", { id: 123 }, function(response) {
// You can do whatever you want with the response here, like...
$(".container").html(response);
});
// The response variable is async, so you wont be able to use it outside that scope
});
然后,在你的后端,则必须接收该端点的请求的功能,像:
function(request) {
var bookID = request.id;
// Fetch book data from your database
var bookData = YourModelMethod.getBook(bookID);
return "<div>" + bookData.title + "</div>";
}
你可以在jQuery文档中找到更多细节:https://api.jquery.com/jquery.get/
但这是一种阿贾克斯请求。我需要点击“/ books”路线并执行路线内的代码。而且我还会追加一个查询字符串 - “/ books?id = kjdhdjh”。希望我的问题很明确。 –
我不太明白你想要达到什么目的,你想在提出请求之前还是之后追加ID?如果您试图获取呈现特定图书的代码,那么当您执行获取请求时,您可以将该ID作为参数传递,我将更新示例 –
所以基本上你的问题是“如何做一个ge t请求“,并且与bootstrap模式完全不相关。对? – Dekel
[Ajax教程的帖子和获取]的可能重复(https://stackoverflow.com/questions/9436534/ajax-tutorial-for-post-and-get) – Dekel
我需要一个正常的请求发生,它应该执行路由中的代码并呈现页面。请帮忙。 –