非法调用(jQuery) [英] Illegal Invocation (jQuery)
本文介绍了非法调用(jQuery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
可能重复:
$ .post抛出非法调用"
Possible Duplicate:
$.post throwing "Illegal invocation "
尝试提交AJAX请求时遇到以下错误:Uncaught TypeError:非法调用.这是代码: http://pastie.org/private/px6qinlgydv6cgcwrghvxw ,如果我删除了该问题,该问题就会消失$ .ajax()函数.
I'm getting the following error when trying to submit a AJAX request: Uncaught TypeError: Illegal invocation. Here's the code: http://pastie.org/private/px6qinlgydv6cgcwrghvxw and the issue disappears if I remove the $.ajax() function.
<script type="text/javascript">
$(document).ready(function() {
$('.inquiry-button').on('click', function(e) {
if($('.x-box ul li').length > 0) {
$('.x-box, .x-box-bottom').fadeOut('slow', function() {
$('.inquiry-form, .inquiry-buttons').fadeIn();
})
}
})
$('.edit-inquiry-submit').on('click', function(e){
e.preventDefault();
$('.inquiry-form, .inquiry-buttons').fadeOut('slow', function() {
$('.x-box, .x-box-bottom').fadeIn();
})
})
$('.inquiry-submit').on('click', function(e) {
e.preventDefault();
var valid = 1;
var name = $('#your_name');
var email = $('#your_email');
var company = $('#company_name');
if (!name.val() && valid == 1) {
var valid = 0;
name.focus();
alert('Please provide your Name');
}
if (!email.val() && valid == 1) {
var valid = 0;
email.focus();
alert('Please provide your Email Address');
}
if (!company.val() && valid == 1) {
// var valid = 0;
// company.focus();
// alert('Please provide your Company Name');
}
if (valid == 1) {
$('#i-form, .inquiry-buttons').fadeOut('', function() {
$('.inquiry-thank-you').fadeIn('', function() {
$.ajax({
url: 'http://projectsxxxxxdev.com/cooling/wp-admin/admin-ajax.php',
data: {'action' : 'sendProducts', 'name' : name, 'email' : email, 'company' : company},
dataType : 'json',
type: 'POST',
success : function(data){
console.log(data)
}})
});
});
}
})
})
</script>
推荐答案
您正尝试在数据参数中传递jQuery对象,请调用.val()
以使用其值
You're trying to pass jQuery objects in your data parameter, call .val()
to use their values
$.ajax({
url: 'http://projectsxxxxxdev.com/cooling/wp-admin/admin-ajax.php',
data: {'action' : 'sendProducts', 'name' : name.val(), 'email' : email.val(), 'company' : company.val()},
dataType : 'json',
type: 'POST',
success : function(data){
console.log(data)
}
});
这篇关于非法调用(jQuery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文