代码之家  ›  专栏  ›  技术社区  ›  shubham kapoor

在mysql中插入数据而不重新加载页面,并在同一页面获取数据

  •  0
  • shubham kapoor  · 技术社区  · 7 年前

    我正在使用ajax,但它的行为不同。我只想知道我应该 在里面 模型 ,请 查看 我是说, 控制器 是的。

    这个while包含两个操作:插入和从数据库中获取数据。

    ![In image their is subject and textarea as input.When i click submit the input dispaly in comment which is just above the Subject input ] 1

    查看

       <form action="" method="POST">
       <input type="hidden" name="myId" id="myId" value="" />
       <div class="form-group px-4">
           <label for="subject">Subject</label>
           <input type="text" id="js_subject" name="js_subject">
       </div>
       <div class="form-group px-4">
          <label for="exampleFormControlTextarea1">Example textarea</label>
          <textarea class="form-control" name = "js_text" id="js_text" rows="3"></textarea>
       </div>
      <input type="submit" id="comment-info" value="submit" name="submit" class="btn btn-primary">
       </form>
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Laki96    7 年前

    使用jquery ajax请求,在somepage.php上使用if和else进行插入、选择和 回显一些消息给两者和die();

    $('form').on('submit', function(event){
                    event.preventDefault();
                    $.ajax({
                            type:'post',
                            url:'somepage.php',
                            data:$(this).serialize(),
                            success:function(data){
                            var tmp = data;
                           if(data = "message1"){
                              //do whatever
                           }else if(data = "message2"){
                             //do whatever
    
    
                            }
                        })
    
                        });
    
    推荐文章