jQuery - 非法调用 [英] jQuery - Illegal invocation
本文介绍了jQuery - 非法调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
jQuery v1.7.2
我有这个功能,它在执行时给我以下错误:
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 调用中删除 data
,它会起作用.. 有什么建议吗?
If I remove data
from ajax call, it works .. any suggestions?
谢谢!
推荐答案
我认为您需要将字符串作为数据值.这可能是 jQuery 内部的某些内容没有正确编码/序列化 To &来自对象.
I think you need to have strings as the data values. It's likely something internally within jQuery that isn't encoding/serializing correctly the To & From Objects.
试试:
var data = {
from : from.val(),
to : to.val(),
speed : speed
};
请注意以下内容:
$(from).css(...
$(to).css(
您不需要像 To & 那样的 jQuery 包装器From 已经是 jQuery 对象了.
You don't need the jQuery wrapper as To & From are already jQuery objects.
这篇关于jQuery - 非法调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文