dongtong848825 2015-11-12 15:11
浏览 100

发送回好的JSON响应时,PHP处理页面404'

Have a sendmail.php page that i'm calling via ajax on a WordPress site.

This is the basics of how it looks:

if ($_POST) {

    foreach($_POST as $field => $val) {
        if ($val == '') {
            $jsonReturn = ['success' => false, 'message' => 'Validation errors whilst processing your form, please go back and check.'];
            echo json_encode($jsonReturn);
            die();
        }
    }

    if ($noErrors) { // set elsewhere, but works okay
        /*
            Send an email
        */

        if ($mail->send()){
            $jsonReturn = ['success' => true, 'message' => "Thank you, message sent."];
            echo json_encode($jsonReturn);
        }
    }

} else {
    header("Location: /");
    die();
}

If the 'validation' fails at the top of the page, I get a 200 page back containing the JSON return of success false.

However, if I pass validation and send the email thens end the json return it 404's the page.

I tested also by putting:

$jsonReturn = ['success' => true, 'message' => "Thank you, message sent."];
echo json_encode($jsonReturn);

Directly under the first foreach and it also 404's. So im guessing there is something wrong with that?

Any help.

  • 写回答

1条回答 默认 最新

  • dpblwmh5218 2015-11-12 17:15
    关注

    Sorted, the input field has a name of "name".

    Changing that worked, speaking to a colleague it appears that WordPress has a certain set of field names reserved for its queries. In this case it was seeing the field name and sending the request off to another page which doesn't exist.

    Im sure a person with more knowledge at WP can explain better, but for now if anyone comes across this issue just make sure to check the input names.

    评论

报告相同问题?

悬赏问题

  • ¥15 MATLAB怎么通过柱坐标变换画开口是圆形的旋转抛物面?
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥30 用arduino开发esp32控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题