• PHP ajax基础


    后台对数据处理,并返回前台:

    <?php
    //接收
    $action = $_GET['action'];
    if ($action == 'orderID') {
        
        $orderID = trim($_POST['orderID']);
        if($orderID != ""){
            $sql = "INSERT INTO `db`.`tb` (`id`, `orderID`, `add_time`) VALUES (NULL, '$orderID', '$time')";
            if (mysql_query($sql)) {
                echo "1";    
            }
        }    
            
    } 
    ?>

     前台取值:

    //文本框取值
    var name = $("input[name='name']").val();
    
    //radio 单选项取值
    var list01 = $("input[name='list01']:checked").val();
    
    //ajax 
    $.ajax({
                type: "POST",
                url: "question.php?action=orderID",
                dataType: "json",
                data: {"orderID":orderID},
                beforeSend: function(){
                    console.log("loading...");        
                },
                success: function(back){
                    
                    if(back==1){    
                        //location.reload();
                        console.log("ok");
                        step1.hide();
                        step2.fadeIn(500);
                                            
                    }else{
                        console.log("no");
                    }
                }
            });
    //JS随机输出提示
    var msgArr = new Array("请填完再提交哦!","还有没填完哦!","没填完就提交?还是检查下吧!","检查下,还是填完吧!","不能有空哦!");
    var num = parseInt(Math.random() * msgArr.length);  
    var msg = msgArr[num];
    alert(msg);
  • 相关阅读:
    格式布局
    tp框架之文件上传
    tp框架之验证码
    tp框架之自动验证表单
    tp框架之留言板练习
    tp框架之session
    tp框架之登录验证
    tp框架之函数调用
    tp框架之分页与第三方类的应用
    tp框架之AJAX
  • 原文地址:https://www.cnblogs.com/xiangsj/p/6060996.html
Copyright © 2020-2023  润新知