非法调用错误 [英] Illegal invocation Error

查看:175
本文介绍了非法调用错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的脚本页面上只有一个函数,它给了我这个错误: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆