非法调用错误 [英] Illegal invocation Error
问题描述
我的脚本页面上只有一个函数,它给了我这个错误:Uncaught TypeError:非法调用.老实说,我以前从未见过此错误,而且我在网上发现的其他任何情况似乎都不适用于我.我的jQuery在下面,我认为没有其他必要,但请告诉我,我可以发布其他内容.
I only have one function in my scripts page, and it is giving me this error: Uncaught TypeError: Illegal invocation. To be honest, I've never seen this error before, and none of the other cases that I found online seemed to apply to me. My jquery is below, and I don't think any other pieces are necessary, but let me know and I can post other parts.
$(document).ready(function () {
/*----UPDATE BOX REQUEST----*/
$(".boxesChange").live("click", function () {
entry = $(this).closest("tr");
delivered = $(entry).find("#delivered");
if ((delivered).is(":checked")) {
deliveredBoolean = "1";
} else {
deliveredBoolean = "0";
}
boxesDelivered = $(entry).find("#boxesDelivered").val();
bubbleWrapDelivered = $(entry).find("#bubbleWrapDelivered").val();
supplyRequestId = $(entry).find(".boxesSupplyRequestId").val();
$.post('boxesChange.php', {
'delivered': delivered,
'boxesDelivered': boxesDelivered,
'bubbleWrapDelivered': bubbleWrapDelivered,
'supplyRequestId': supplyRequestId
}, function (response) {
$(this).closest(".boxesScheduleEntry").css("background-color", "#ccffcc");
});
return false;
});
});
推荐答案
问题出在您的$.post
调用中.您正在尝试将'delivered'
设置为delivered
,这是一个jQuery对象,我假设您的意思是deliveredBoolean
.
The problem is in your $.post
call. You're trying to set 'delivered'
to delivered
, which is a jQuery object, I assume you meant deliveredBoolean
.
此外,在回调函数this
中,您所认为的不是它,而是jqXHR对象,而不是元素.
Also, in the callback function this
is not what you think it is, it's the jqXHR object, not the element.
var $this = $(this);
$.post(
'boxesChange.php',
{
'delivered': deliveredBoolean,
'boxesDelivered': boxesDelivered,
'bubbleWrapDelivered': bubbleWrapDelivered,
'supplyRequestId': supplyRequestId
},
function (response) {
$this.closest(".boxesScheduleEntry").css("background-color", "#ccffcc");
}
);
这篇关于非法调用错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!