WordPress admin-ajax.php文件中的Ajax``错误请求''错误400

时间:2018-08-08 03:59:58

标签: php ajax wordpress

我正在尝试在我的一个wordpress页面文件中创建一个用户注册页面。当调用ajax并使用admin-ajax.php文件作为URL时,我遇到了400错误。发生ajax调用的功能如下所示:

  function checkusername(){
    var u = _("username").value;
    if(u != ""){
        _("unamestatus").innerHTML = 'checking ...';
        var ajax = ajaxObj("POST", "<?php echo admin_url('admin-ajax.php'); ?>");
        ajax.onreadystatechange = function() {
            if(ajaxReturn(ajax) == true) {
                _("unamestatus").innerHTML = ajax.responseText;
            }
        }
        ajax.send("usernamecheck="+u);
    }
}
function signup(){
    var u = _("username").value;
    var e = _("email").value;
    var p1 = _("pass1").value;
    var p2 = _("pass2").value;
    var fn = _("fname").value;
    var ln = _("lname").value;
    var m = _("major").value;
    var phone = _("phone").value;
    var blazeid = _("blazerid").value;
    var status = _("status");
    if(p1 != p2){
        status.innerHTML = "Your password fields do not match";
    }else {
        _("signupbtn").style.display = "none";
        status.innerHTML = 'please wait ...';
        var ajax = ajaxObj("POST", "<?php echo admin_url('admin-ajax.php'); ?>");
        ajax.onreadystatechange = function() {
            if(ajaxReturn(ajax) == true) {
                if(ajax.responseText != "signup_success"){
                    status.innerHTML = ajax.responseText;
                    _("signupbtn").style.display = "block";
                } else {
                    window.scrollTo(0,0);
                    _("signupform").innerHTML = "OK "+u+", check your email inbox and junk mail box at <u>"+e+"</u> in a moment to complete the sign up process by activating your account. You will not be able to do anything on the site until you successfully activate your account.";
                }
            }
        }
        ajax.send("u="+u+"&e="+e+"&p="+p1+"&fn="+fn+"&ln="+ln+"&m"+m+"&phone"+phone+"&blazeid"+blazeid);
    }
}

这位于主题目录下我的一个页面文件内。有没有人可以帮助我呢?谢谢。

1 个答案:

答案 0 :(得分:0)

您需要以这种方式定义Ajax函数

 public function readbyid($id){

    $test = DB::table('notifications')->where('id','=', $id)->get();

 dd($test);}