可能重复:
$.post 抛出“非法调用”</a>
尝试提交 AJAX 请求时出现以下错误:Uncaught TypeError: Illegal invocation。这是代码:http ://pastie.org/private/px6qinlgydv6cgcwrghvxw ,如果我删除 $.ajax() 函数,问题就会消失。
<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>