简体   繁体   English

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

[英]Ajax 'bad request' error 400 in wordpress admin-ajax.php file

I am trying to create a user registration page within one of my wordpress page files.我正在尝试在我的 wordpress 页面文件之一中创建用户注册页面。 When making a call to ajax and using the admin-ajax.php file as the url, i am encountering a 400 error.在调用 ajax 并使用 admin-ajax.php 文件作为 url 时,我遇到了 400 错误。 The functions where the ajax calls are occurring are shown below:发生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);
    }
}

This is located inside one of my page files within the theme directory.这位于我的主题目录中的一个页面文件中。 Is there anyone that can help me with this?有没有人可以帮我解决这个问题? Thank you.谢谢你。

You need to define Ajax function in this way需要这样定义ajax函数

function checkusername(){
}
add_action( 'wp_ajax_checkusername', 'checkusername' );
add_action( 'wp_ajax_nopriv_checkusername', 'checkusername' );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM