jQuery的 - 非法调用 [英] jQuery - Illegal invocation

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

问题描述

jQuery的V1.7.2

我有这个funcion这是给我下面的错误而执行

I have this funcion that is giving me the following error while executing :

Uncaught TypeError: Illegal invocation

下面的功能:

$('form[name="twp-tool-distance-form"]').on('submit', function(e) {
    e.preventDefault();

    var from = $('form[name="twp-tool-distance-form"] input[name="from"]');
    var to = $('form[name="twp-tool-distance-form"] input[name="to"]');
    var unit = $('form[name="twp-tool-distance-form"] input[name="unit"]');
    var speed = game.unit.speed($(unit).val());

    if (!/^\d{3}\|\d{3}$/.test($(from).val()))
    {
        $(from).css('border-color', 'red');
        return false;
    }

    if (!/^\d{3}\|\d{3}$/.test($(to).val()))
    {
        $(to).css('border-color', 'red');
        return false;
    }

    var data = {
        from : from,
        to : to,
        speed : speed
    };

    $.ajax({
        url : base_url+'index.php',
        type: 'POST',
        dataType: 'json',
        data: data,
        cache : false
    }).done(function(response) {
        alert(response);
    });

    return false;
});

如果我删除数据从Ajax调用,它的工作原理..有什么建议?

If I remove data from ajax call, it works .. any suggestions?

谢谢!

推荐答案

我认为你需要有串的数据值。它有可能在内部jQuery的东西没有编码/序列正确的到&放大器;从对象。

I think you need to have strings as the data values. Its likely something internally within jQuery isn't encoding/serializing correctly the To & From Objects.

尝试:

var data = {
    from : from.val(),
    to : to.val(),
    speed : speed
};

的通知还对行

Notice also on the lines

$(from).css(...
$(to).css(

您不需要jQuery的包装为&放大器;从已经jQuery的对象。

you don't need the jQuery wrapper as To & From are already jQuery objects.

这篇关于jQuery的 - 非法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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