Uncaught TypeError: Cannot read property 'ajax' of undefined

女生的网名这么多〃 提交于 2020-12-29 10:05:27

问题


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

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


回答1:


Did you try doing what the rest of the code is doing, using 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 $

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



回答2:


I can't solve the problem using jQuery instead of $.

In my case, I add the source jQuery.js and solve the problem, like

<script src="<%= Page.ResolveUrl("~/JS/jQuery.js") %>"></script>


来源:https://stackoverflow.com/questions/23588941/uncaught-typeerror-cannot-read-property-ajax-of-undefined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!