php表单上传

表单上传

html:

<form action="php地址" method="post">
       <label>
           用户名: <input type="text" name = "user">
       </label>
       <br>
       <label>
           密&emsp;码: <input type="password" name="pwd">
       </label>
       <br>
       <input type="submit" value="提交" id="btn">
   </form>
   <span id="info">用户名或者密码错误</span>

js:

$('form').on('submit',function(e){
            e.preventDefault();
        })
$("#btn").on("click",function(e){
      //用ajax上传
      $.ajax({
          type:"POST",
          url:  php地址 ,
          data:{
                user:$.trim($('input[name=user]').val()),
                user:$.trim($('input[name=pwd]').val()),
                },
          dataType:'json',
          success:function(res){
                  console.log(res);
                  //status==1时上传成功
                  if(res.status==1){
                         setTimeout(function(){
                          location.href = "success.html";
                        },3000);
                  }else{
                      $("#info").show();
                  }
              },
          //错误信息
            error:function(err){
                    console.log(err);
                }
            })
          })

php:

header("Content-Type:text/html;charset=utf8");
$user = $_POST['user'];
$pwd = $_POST['pwd'];
//省略数据库查询

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容