后台对数据处理,并返回前台:
<?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);