我試圖通過.ajax調用檢索數據並將響應html代碼添加到引導模態主體。但我一直接收此錯誤:jQuery .ajax語法錯誤,無法識別的表達式
的jquery-3.1.0.min.js:2未被捕獲的錯誤:語法錯誤,不能識別的表達式:http://localhost/menu/create
其實我接收響應所需的數據,但由於這錯誤,數據無法顯示在模態窗口上。
這是我的代碼。當我點擊一個鏈接時,ajax調用返回一個html表單並將其插入到模態主體中。然後顯示模式窗口。
<a href="{{route('menu.create')}}" class="btn btn-default pull-right show-new-menu-item-modal" data-toggle="modal">New Menu Item</a>
$('body').on('click', '.show-new-menu-item-modal', function(event) {
event.preventDefault();
$.ajax({
url: $(this).attr('href'),
dataType: 'html',
success: function(response) {
$("#new-menu-item-body").html(response);
}
});
$('#new-menu-item-modal').modal('show');
});
我一直在使用谷歌搜索和更改代碼幾個小時,但仍然沒有運氣。如果有人能給我一些想法,我將非常感激。提前致謝!
嘗試在您的ajax調用結束時添加返回false –