weixin_33682790 2015-11-04 23:57 采纳率: 0%
浏览 27

使用PHP的Ajax调用

I am trying to build a simple sign up form using AJAX and PHP. On submitting the form the submit_create_user_form() function is called.

This AJAX function calls ajax_calls.php page.

function submit_create_user_form(){
    var u = document.getElementById("org_name").value;

        xhttp.onreadystatechange = function(){
            if (xhttp.readyState == 4 && xhttp.status == 200) {
                var result =xhttp.responseText; 
                //status.innerHTML=xhttp.responseText;
                if(result==="Successful"){
                    //window.scrollTo(0,0);
                    document.getElementById('main').innerHTML ="An activation link has been sent to the new user's E-mail ID";
                }
                else
                    status.innerHTML="Some error Occurred!!";
            }       
          }
          xhttp.open("POST", "ajax_calls.php", true);
          xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

          xhttp.send("q="+u);


}

ajax_calls.php echoes "Successful" which is checked with xhttp.responseText in the above code snippet. Even then the output is "Some error occured."

ajax_calls.php:

if( isset($_POST["q"]) ){
    echo "Successful";
}

could someone help with this? Thanks!

  • 写回答

2条回答 默认 最新

  • weixin_33726318 2015-11-05 00:08
    关注

    This is a jQuery code

    $(document).ready(function(e){
            var u=$('#org_name').val();
            $.post("ajax_calls.php",{q:u},function(data,message,xhr){
                                    if(message==='success'){
                                        $('#main').text(data);
                                    }
                                });
    
        });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 三因素重复测量数据R语句编写,不存在交互作用
  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表