我有一个功能,可以在表单提交时调用它来发送ajax请求。问题是,当我尝试提交表单时,出现以下错误:“ checkCustomerExists未定义”另外奇怪的是,我有一个暂存和生产站点,它们当前是相同的,并且暂存站点无法正常工作问题,但生产站点就是有问题的站点。这是到目前为止我在两个站点上都拥有的内容:
<script>
function checkCustomerExists(){
var phone = $('input[name=phone]').val();
var email = $('input[name=email]').val();
loadingModal();
if (phone !== '' && email !== '' && !checkedIfAccount){
var data = {
email,
phone
};
checkedIfAccount = true;
$.ajax({
url: "{{ shop.metafields.API.doesCustExist }}",
data: JSON.stringify(data),
method: "POST",
dataType: "json",
success: function(json){
if (json.exists){
if(!json.active){
var contactName;
var contactType;
if (json.email){
contactName = json.email;
contactType = 'email';
} else if(json.phone) {
contactName = json.phone;
contactType = 'phone number';
}
$('#error-message').html('Your account with the '+contactType+' <span>'+contactName+'</span> has not yet been activated. An email has been sent to you with an activation link to finish creating your account.');
$('#account-exists-modal').modal('show');
}
else if (json.email){
$('#error-message').html('There is an existing account with the registered email <span style="color: red">'+json.email+'</span>. Please Log In with the provided form.');
$('#account-exists-modal').modal('show');
} else if (json.phone){
$('#error-message').html('There is an existing account with the phone number <span style="color: red">'+json.phone.replace(/^\(?([0-9]{3})\)?(\s)?[-.●]?([0-9]{3})(\s)?[-.●]?([0-9]{4})$/, '($1) $3-$5')+'</span>. Please Log In with the provided form.');
$('#account-exists-modal').modal('show');
}
doesAcctExist = true;
} else {
addCustomeToPro();
}
});
checkedIfAccount = true;
}
}
</script>
<script>
var checkedIfAccount = false;
var doesAcctExist = false;
$('#add_prof').submit(function(e){
e.preventDefault();
var professions = [];
$('.prof_check:checkbox:checked').each(function(){
professions.push('Profession:' + $(this).val());
});
if (!validateForm(professions)) {
unloadButton();
return false;
}
checkCustomerExists();
});
</script>
我不知道为什么一个有效而另一个无效。它们也都在Shopify商店中。任何帮助表示赞赏。