我需要在我的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
我需要一個正常的請求發生,它應該執行路由中的代碼並呈現頁面。請幫忙。 –