【发布时间】:2020-02-16 18:24:24
【问题描述】:
我的 Wordpress 页面上有一个脚本,通过可视页面构建器中的代码块实现。我想知道的是,如何通过正确的 URL 来访问我的 PHP 文件?由于它位于页面构建器的块中,因此我认为我不能使用 ajax_admin 作为 url,因为该文件从未入队。
$("#submit_button").click(function(e,features,totalcost){
e.preventDefault();
console.log('clicked')
$.ajax({
type: "POST",
url: '/wp-content/plugins/estimate/estimate.php',
data: {
action: 'submitWizard',
// add your parameters here
features: features,
total:totalcost,
email:$("#exampleInputEmail1").value,
name:$("#exampleInputPassword1").value,
message:$("#exampleFormControlTextarea1").value,
},
success: function(response){
console.log(response);
}
});
})
我有一个插件,叫做estimate,代码如下:
add_action( 'wp_ajax_submitWizard', 'process_estimate' );
function process_estimate(){
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$features = $_POST['features'];
$total = $_POST['total'];
wp_mail( 'charlespettisappdevelopment@gmail.com', 'New Submission!', "
$name,
$email,
$message,
$features,
$total,
");
}
【问题讨论】:
-
那么问题出在哪里?
-
@ezra ,抱歉,这可能有用。尝试调用此函数时出现 500 个服务器错误。我想我的问题是,如何在 jquery 帖子设置中传递正确的 URL。
-
a 500 post 错误意味着服务器端的错误。这意味着您的 php 代码存在问题。另外,去chrome开发者工具看看post参数是否发送正确
标签: javascript php jquery ajax wordpress