【问题标题】:Please Wait message in Ajax请在 Ajax 中等待消息
【发布时间】:2015-12-25 22:37:35
【问题描述】:

我对@9​​87654321@ 和js 还是个小新人。我正在尝试将数据发送到functions.php?action=signp,但代码显示“请稍候”,然后什么也没有发生。我的代码如下:

<script type="text/javascript">
function signup()
{
    var ufname = document.getElementById("fName").value;
    var ulname = document.getElementById("lName").value;
    var e = document.getElementById("email").value;
    var p1 = document.getElementById("pass1").value;
    var p2 = document.getElementById("pass2").value;
    var status = document.getElementById("statusSignUp");
    if(ufname == "" || ulname == "" || e == "" || p1 == "" || p2 == "")
    {
        status.innerHTML = "Fill out all of the form data";
    }
    else
    {
        document.getElementById("signupbtn").style.display = "none";
        status.innerHTML = 'please wait ...';
        var ajax = ajaxObj("POST", "functions.php?action=signp");
        ajax.onreadystatechange = function()
        {
            if(ajaxReturn(ajax) == true)
            {
                if(ajax.responseText != "signup_success")
                {
                    status.innerHTML = ajax.responseText;
                    document.getElementById("signupbtn").style.display = "block";
                } 
                else
                {
                    window.scrollTo(0,0);
                    document.getElementById("signupform").innerHTML = "Yippieeee";
                }
            }
        }
        //xhttp.open("POST", "functions.php?action=signp", true);
        ajax.send("&fName="+fName+"&lName="+lName+"&email="+email+" pass1="+pass1);
    }
}
</script>

有人请告诉我代码有什么问题吗?

【问题讨论】:

  • 浏览器控制台说什么?我假设没有定义像 ajax 这样的东西,因为它被注释掉了。
  • 先生,我已经解决了。我只是在检查 xhttp 是否有效,或者没有评论“var ajax =....”。请帮我处理这段代码
  • ajaxObj() 函数有什么作用?

标签: php html ajax


【解决方案1】:

我会给你一个非常简单的解决方案。使用 jQuery Ajax。它是一个非常易于使用的库。

http://api.jquery.com/jquery.ajax/

【讨论】:

    【解决方案2】:

    这里是我如何使用我的网站,希望我能给你一些关于 jquery ajax 的见解: (为了清楚起见,所有的 url 和变量都被简化了

    if(error_flag== 0)//i checked for errors before execute ajax.this is error flag that counts error if any error occurs it will shot its message.
        {
            e.preventDefault();
            $('#registerModal').modal('show');//i show modal to user.In that modal i have spining icon and text that tells them to wait
            //ajax post to register.php
            $.post("register.php",
            $("#registerForm").serialize(),
            function(durum){
                durum = jQuery.parseJSON(durum);
                $("#registerMesaj_id").html(durum.Msj);//if all went succesfull it will say success message.ıf not it will tell user some error
            });
        }else{
            e.preventDefault();
            console.log(error_message);
        }
    

    【讨论】:

      猜你喜欢
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 2020-07-02
      • 1970-01-01
      • 2018-08-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多