未捕获的TypeError:无法读取未定义的属性'ajax' [英] Uncaught TypeError: Cannot read property 'ajax' of undefined
本文介绍了未捕获的TypeError:无法读取未定义的属性'ajax'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试通过POST调用使用AJAX从表中删除项目.
I tried deleting an item from a table with AJAX via a POST call.
///// DELETE INDIVIDUAL ROW IN A TABLE /////
jQuery('.stdtable .delete').live('click', function (e) {
//var newsId1 = $(this).attr("title");
e.preventDefault();
var p = jQuery(this).parents('tr');
if (p.next().hasClass('togglerow'))
p.next().remove();
p.fadeOut(function () {
jQuery(this).remove();
});
$.ajax({
URL: "/AdminPanel/News/DeleteNews",
data: { "newsId": 1 },
dataType: "json",
type: "POST",
success: function (msg) {
alert(msg);
}
});
在这段代码中,我得到 Uncaught TypeError:无法读取未定义的属性'ajax'.
In this code I get Uncaught TypeError: Cannot read property 'ajax' of undefined.
推荐答案
您尝试使用jQuery
jQuery.ajax({
URL: "/AdminPanel/News/DeleteNews",
data: { "newsId": 1 },
dataType: "json",
type: "POST",
success: function (msg) {
alert(msg);
}
您可以将代码包装在DOM ready函数中,该函数在函数范围内在本地设置$
的值,这样您就可以始终使用$
You can wrap your code in a DOM ready function that sets the value of $
locally in the function scope, that way you can always use $
jQuery(function($) {
// code goes here
});
这篇关于未捕获的TypeError:无法读取未定义的属性'ajax'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文