jQuery v1.7.2我有這個功能,在執(zhí)行時給我以下錯誤: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;});如果我data從ajax調(diào)用中刪除,它可以..有什么建議嗎?謝謝!
2 回答

慕桂英4014372
TA貢獻1871條經(jīng)驗 獲得超13個贊
我認為您需要將字符串作為數(shù)據(jù)值。可能是jQuery內(nèi)部的某些內(nèi)容未能正確地對To&From對象進行編碼/序列化。
嘗試:
var data = {
from : from.val(),
to : to.val(),
speed : speed
};
還要注意以下行:
$(from).css(...
$(to).css(
您不需要jQuery包裝器,因為To&From已經(jīng)是jQuery對象。

幕布斯6054654
TA貢獻1876條經(jīng)驗 獲得超7個贊
嘗試設(shè)置processData:在像這樣的ajax設(shè)置中為false
$.ajax({
url : base_url+'index.php',
type: 'POST',
dataType: 'json',
data: data,
cache : false,
processData: false
}).done(function(response) {
alert(response);
});
- 2 回答
- 0 關(guān)注
- 651 瀏覽
添加回答
舉報
0/150
提交
取消