浏览文章

文章信息

Uncaught TypeError: Cannot read properties of undefined (reading 'createDocumentFragment') 930

报错:

Uncaught TypeError: Cannot read properties of undefined (reading 'createDocumentFragment')

源代码


$.ajax({
url: '{{ catalog }}index.php?route=api/order/ship&api_token={{ api_token }}&store_id={{ store_id }}&order_id=' + $('#order-ship-container').data('order-id'),
dataType: 'json',
data:need_data,
beforeSend: function () {
$(this).button('loading');
},
complete: function () {
$(this).button('reset');
},

,......

原因:

在ajax中使用了this对象,此时this对象指向的是ajax,而不是外层this.

解决:

let button = $(this)
$.ajax({
url: '{{ catalog }}index.php?route=api/order/ship&api_token={{ api_token }}&store_id={{ store_id }}&order_id=' + $('#order-ship-container').data('order-id'),
dataType: 'json',
data:need_data,
beforeSend: function () {
button.button('loading');
},
complete: function () {
button.button('reset');
},......

原创