Jquery $.post()已停止在函数内工作
我使用jQueryAJAXPOST函数在数据库中输入新行,然后在.done上输出一些HTML 它可以很好地工作,不需要将其放入函数中。但由于某种原因,当我将其添加到函数中时,它停止了工作。有人能帮我弄清楚吗 下面是我的代码 功能页: 索引页:Jquery $.post()已停止在函数内工作,jquery,Jquery,我使用jQueryAJAXPOST函数在数据库中输入新行,然后在.done上输出一些HTML 它可以很好地工作,不需要将其放入函数中。但由于某种原因,当我将其添加到函数中时,它停止了工作。有人能帮我弄清楚吗 下面是我的代码 功能页: 索引页: 当您从on click函数内部调用add_items时,它不再表示add_items函数内部的元素。尝试将元素传入函数 function page function add_items(el){ var id = ($(el).attr("id
当您从on click函数内部调用add_items时,它不再表示add_items函数内部的元素。尝试将元素传入函数
function page
function add_items(el){
var id = ($(el).attr("id"));
//Insert a new row using an ajax post method, post the the id to reference
//under which category the menu item should go under
var adtnl_item = $.post("ItemCreate.php", {id : id })
.fail(function(){
console.log( "New Row Can't be added" );
})
//Append the new menu item input fields to the div class
//.menu_item_wrapper that has an id of the mainØ category ID
.done(function(data) {
return $('.menu_item_wrapper[id="' + id + '"]').append(data);
});
}
index page
$(".add_item").on("click", function(){
add_items(this);
});
请看发生了什么事?控制台中有错误吗?还要检查ajax请求-在Chrome->developer tools->Networker中,或者可以将其保存在处理程序函数中,并将处理程序作为引用$传递;
$(".add_item").on("click", function(){
add_items();
});
function page
function add_items(el){
var id = ($(el).attr("id"));
//Insert a new row using an ajax post method, post the the id to reference
//under which category the menu item should go under
var adtnl_item = $.post("ItemCreate.php", {id : id })
.fail(function(){
console.log( "New Row Can't be added" );
})
//Append the new menu item input fields to the div class
//.menu_item_wrapper that has an id of the mainØ category ID
.done(function(data) {
return $('.menu_item_wrapper[id="' + id + '"]').append(data);
});
}
index page
$(".add_item").on("click", function(){
add_items(this);
});