php-Ajax错误:WordPress联系表单7上位置0的JSON中的意外令牌<在JSON中
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了php-Ajax错误:WordPress联系表单7上位置0的JSON中的意外令牌<在JSON中,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2462字,纯文字阅读大概需要4分钟。
内容图文
![php-Ajax错误:WordPress联系表单7上位置0的JSON中的意外令牌<在JSON中](/upload/InfoBanner/zyjiaocheng/685/396d564a420747fea0693b7dbfccda92.jpg)
发布联系表单时出现奇怪的问题.
加载图标保持加载状态,并且不提交表单.
电子邮件已发送,我的before_send_mail函数也起作用.奇怪的是,当我取消注释before_send_mail函数时,它没有显示任何错误.因此,这可能是我的代码中的某些内容.
但是,首页并没有改变状态,并一直显示加载图标.
错误消息说:
<div class="ajax-error">Unexpected token < in JSON at position 0</div>
你们能帮我吗?在下面,您将找到before_send函数.
add_action( 'wpcf7_before_send_mail', 'form_to_crm' );
function form_to_crm( $cf7 ) {
$wpcf7 = WPCF7_ContactForm::get_current();
/* Uw naam => first_name */ $first_name = $_POST["your-name"];
/* Bedrijf => company_name */ $company = $_POST["bedrijf"];
/* Email => email */ $email = $_POST["email"];
/* Adres => address */ $address = $_POST["adres"];
/* Nummer* => number */ $number = $_POST["huisnummer"];
/* Postcode => postcode */ $postcode = $_POST["postcode"];
/* Woonplts* => city */ $city = $_POST["woonplaats"];
/* Tel => telephone */ $telephone = $_POST["telefoonnummer"];
if(!empty( $first_name )){ $post_items['first_name'] = $first_name; }
if(!empty( $company )){ $post_items['company_name'] = $company; }
if(!empty( $email )){ $post_items['email'] = $email; }
if(!empty( $address )){ $post_items['address'] = $address; }
if(!empty( $number )){ $post_items['number'] = $number; }
if(!empty( $postcode )){ $post_items['postcode'] = $postcode; }
if(!empty( $city )){ $post_items['city'] = $city; }
if(!empty( $telephone )){ $post_items['telephone'] = $telephone; }
if(!empty($postcode) && !empty($number))
{
$ch = curl_init();
if ( curl_error($ch) != "" )
{
return;
}
$post_string = json_encode($post_items);
$con_url = 'valid api url';
curl_setopt($ch, CURLOPT_URL, $con_url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
"Content-Type: application/json",
"Authorization: Token XXX (censored)"
));
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post_string);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
$output = curl_exec($ch);
file_put_contents("curlerror.txt", $output);
curl_close($ch);
}
return $output;
}
解决方法:
在浏览器控制台中,ajax调用未作为错误列出.但是,通话中出现错误.感谢@JAAulde向我指出这一点.
内容总结
以上是互联网集市为您收集整理的php-Ajax错误:WordPress联系表单7上位置0的JSON中的意外令牌<在JSON中全部内容,希望文章能够帮你解决php-Ajax错误:WordPress联系表单7上位置0的JSON中的意外令牌<在JSON中所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。