jQuery 未捕获的类型错误:无法读取未定义的属性“ajax”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23588941/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 02:18:59  来源:igfitidea点击:

Uncaught TypeError: Cannot read property 'ajax' of undefined

jqueryajaxjsonpost

提问by Elvin Mammadov

I tried deleting an item from a table with AJAX via a POST call.

我尝试通过 POST 调用使用 AJAX 从表中删除项目。

///// 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);
}
}); 

In this code I get Uncaught TypeError: Cannot read property 'ajax' of undefined.

在这段代码中,我得到Uncaught TypeError: Cannot read property 'ajax' of undefined

回答by adeneo

Did you try doing what the rest of the code is doing, using jQuery

你有没有尝试做其余代码正在做的事情,使用 jQuery

jQuery.ajax({
  URL: "/AdminPanel/News/DeleteNews",
  data: { "newsId": 1 },
  dataType: "json",
  type: "POST",
  success: function (msg) {
  alert(msg);
}

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 $

您可以将代码包装在一个 DOM 就绪函数中,$该函数在函数作用域中本地设置 的值,这样您就可以始终使用$

jQuery(function($) {
    // code goes here
});