Inserting through AJAX page is refreshing [duplicate]












0
















This question already has an answer here:




  • insert query with ajax without reloading whole page

    2 answers




Inserting the data through AJAX it's working but pages refreshing, why is that give a feedback to fix this issues.



This is my ajax code





 <script>
$(document).ready(function(){
$("#button").click(function(){

var postId=$("#postId").val();
var userId=$("#userId").val();
var postComm=$("#postComments").val();

$.ajax({
url:'../validate/inserPostComm.php',
method:'POST',
data:{
poId:postId,
usId:userId,
poco:postComm
},
success:function(data){
//alert(data);
}
});
});
});
</script>


Here I'm using HTML



<form>
<input type="hidden" id="postId" name="postId" value="<?php echo $_GET["postId"]; ?>">
<input type="hidden" id="userId" name="userId" value="<?php echo $_SESSION["u_id"]; ?>">
<textarea placeholder="Post your comment" id="postComments"></textarea>
<button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
</form>









share|improve this question















marked as duplicate by Carl Binalla, Nick, Community Nov 16 '18 at 9:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 5





    Change the type of button from submit to button

    – Nikhil Aggarwal
    Nov 16 '18 at 7:03











  • is this referencing the same file?

    – Akintunde-Rotimi
    Nov 16 '18 at 7:03











  • Yes it's refreshing the same file..

    – Jerad
    Nov 16 '18 at 7:04











  • I don't get why people are down-voting this post. It's a perfectly legitimate question that catches a lot of new people off guard because it's not an obvious solution.

    – Difster
    Nov 16 '18 at 7:19











  • Also stackoverflow.com/questions/27759380/… and stackoverflow.com/questions/43475937/… and stackoverflow.com/questions/44651947/…

    – Nick
    Nov 16 '18 at 8:06
















0
















This question already has an answer here:




  • insert query with ajax without reloading whole page

    2 answers




Inserting the data through AJAX it's working but pages refreshing, why is that give a feedback to fix this issues.



This is my ajax code





 <script>
$(document).ready(function(){
$("#button").click(function(){

var postId=$("#postId").val();
var userId=$("#userId").val();
var postComm=$("#postComments").val();

$.ajax({
url:'../validate/inserPostComm.php',
method:'POST',
data:{
poId:postId,
usId:userId,
poco:postComm
},
success:function(data){
//alert(data);
}
});
});
});
</script>


Here I'm using HTML



<form>
<input type="hidden" id="postId" name="postId" value="<?php echo $_GET["postId"]; ?>">
<input type="hidden" id="userId" name="userId" value="<?php echo $_SESSION["u_id"]; ?>">
<textarea placeholder="Post your comment" id="postComments"></textarea>
<button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
</form>









share|improve this question















marked as duplicate by Carl Binalla, Nick, Community Nov 16 '18 at 9:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • 5





    Change the type of button from submit to button

    – Nikhil Aggarwal
    Nov 16 '18 at 7:03











  • is this referencing the same file?

    – Akintunde-Rotimi
    Nov 16 '18 at 7:03











  • Yes it's refreshing the same file..

    – Jerad
    Nov 16 '18 at 7:04











  • I don't get why people are down-voting this post. It's a perfectly legitimate question that catches a lot of new people off guard because it's not an obvious solution.

    – Difster
    Nov 16 '18 at 7:19











  • Also stackoverflow.com/questions/27759380/… and stackoverflow.com/questions/43475937/… and stackoverflow.com/questions/44651947/…

    – Nick
    Nov 16 '18 at 8:06














0












0








0


1







This question already has an answer here:




  • insert query with ajax without reloading whole page

    2 answers




Inserting the data through AJAX it's working but pages refreshing, why is that give a feedback to fix this issues.



This is my ajax code





 <script>
$(document).ready(function(){
$("#button").click(function(){

var postId=$("#postId").val();
var userId=$("#userId").val();
var postComm=$("#postComments").val();

$.ajax({
url:'../validate/inserPostComm.php',
method:'POST',
data:{
poId:postId,
usId:userId,
poco:postComm
},
success:function(data){
//alert(data);
}
});
});
});
</script>


Here I'm using HTML



<form>
<input type="hidden" id="postId" name="postId" value="<?php echo $_GET["postId"]; ?>">
<input type="hidden" id="userId" name="userId" value="<?php echo $_SESSION["u_id"]; ?>">
<textarea placeholder="Post your comment" id="postComments"></textarea>
<button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
</form>









share|improve this question

















This question already has an answer here:




  • insert query with ajax without reloading whole page

    2 answers




Inserting the data through AJAX it's working but pages refreshing, why is that give a feedback to fix this issues.



This is my ajax code





 <script>
$(document).ready(function(){
$("#button").click(function(){

var postId=$("#postId").val();
var userId=$("#userId").val();
var postComm=$("#postComments").val();

$.ajax({
url:'../validate/inserPostComm.php',
method:'POST',
data:{
poId:postId,
usId:userId,
poco:postComm
},
success:function(data){
//alert(data);
}
});
});
});
</script>


Here I'm using HTML



<form>
<input type="hidden" id="postId" name="postId" value="<?php echo $_GET["postId"]; ?>">
<input type="hidden" id="userId" name="userId" value="<?php echo $_SESSION["u_id"]; ?>">
<textarea placeholder="Post your comment" id="postComments"></textarea>
<button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
</form>




This question already has an answer here:




  • insert query with ajax without reloading whole page

    2 answers








javascript php jquery ajax






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 8:12









Sayed Mohd Ali

1,5302520




1,5302520










asked Nov 16 '18 at 7:02









JeradJerad

829




829




marked as duplicate by Carl Binalla, Nick, Community Nov 16 '18 at 9:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by Carl Binalla, Nick, Community Nov 16 '18 at 9:15


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 5





    Change the type of button from submit to button

    – Nikhil Aggarwal
    Nov 16 '18 at 7:03











  • is this referencing the same file?

    – Akintunde-Rotimi
    Nov 16 '18 at 7:03











  • Yes it's refreshing the same file..

    – Jerad
    Nov 16 '18 at 7:04











  • I don't get why people are down-voting this post. It's a perfectly legitimate question that catches a lot of new people off guard because it's not an obvious solution.

    – Difster
    Nov 16 '18 at 7:19











  • Also stackoverflow.com/questions/27759380/… and stackoverflow.com/questions/43475937/… and stackoverflow.com/questions/44651947/…

    – Nick
    Nov 16 '18 at 8:06














  • 5





    Change the type of button from submit to button

    – Nikhil Aggarwal
    Nov 16 '18 at 7:03











  • is this referencing the same file?

    – Akintunde-Rotimi
    Nov 16 '18 at 7:03











  • Yes it's refreshing the same file..

    – Jerad
    Nov 16 '18 at 7:04











  • I don't get why people are down-voting this post. It's a perfectly legitimate question that catches a lot of new people off guard because it's not an obvious solution.

    – Difster
    Nov 16 '18 at 7:19











  • Also stackoverflow.com/questions/27759380/… and stackoverflow.com/questions/43475937/… and stackoverflow.com/questions/44651947/…

    – Nick
    Nov 16 '18 at 8:06








5




5





Change the type of button from submit to button

– Nikhil Aggarwal
Nov 16 '18 at 7:03





Change the type of button from submit to button

– Nikhil Aggarwal
Nov 16 '18 at 7:03













is this referencing the same file?

– Akintunde-Rotimi
Nov 16 '18 at 7:03





is this referencing the same file?

– Akintunde-Rotimi
Nov 16 '18 at 7:03













Yes it's refreshing the same file..

– Jerad
Nov 16 '18 at 7:04





Yes it's refreshing the same file..

– Jerad
Nov 16 '18 at 7:04













I don't get why people are down-voting this post. It's a perfectly legitimate question that catches a lot of new people off guard because it's not an obvious solution.

– Difster
Nov 16 '18 at 7:19





I don't get why people are down-voting this post. It's a perfectly legitimate question that catches a lot of new people off guard because it's not an obvious solution.

– Difster
Nov 16 '18 at 7:19













Also stackoverflow.com/questions/27759380/… and stackoverflow.com/questions/43475937/… and stackoverflow.com/questions/44651947/…

– Nick
Nov 16 '18 at 8:06





Also stackoverflow.com/questions/27759380/… and stackoverflow.com/questions/43475937/… and stackoverflow.com/questions/44651947/…

– Nick
Nov 16 '18 at 8:06












5 Answers
5






active

oldest

votes


















2














Easy fix: Add a preventDefault(). Notice the 'e' I added to your click function.



<script>
$(document).ready(function(){
$("#button").click(function(e){
e.preventDefault();

var postId=$("#postId").val();
var userId=$("#userId").val();
var postComm=$("#postComments").val();

$.ajax({
url:'../validate/inserPostComm.php',
method:'POST',
data:{
poId:postId,
usId:userId,
poco:postComm
},
success:function(data){
//alert(data);
}
});
});
});
</script>





share|improve this answer
























  • This will work, also mention changing input type submit to button. :)

    – Smartpal
    Nov 16 '18 at 7:12











  • As a matter of practice, I do this with every button event listener whether it's submit or not. Just a little extra insurance.

    – Difster
    Nov 16 '18 at 7:18











  • It's Working and same like i'm using another ajax code that also same the pages is refreshing.

    – Jerad
    Nov 16 '18 at 7:18











  • @Difster yeah that's.

    – Smartpal
    Nov 16 '18 at 7:19



















5














You are facing it due to the button having input type “Submit”



<button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>


Just change it to normal “button”



<button type="button " id="button"><i class="fa fa-paper-plane"></i></button>





share|improve this answer
























  • exactly type="submit" was the issue, vote up from me

    – TAHA SULTAN TEMURI
    Nov 16 '18 at 7:28



















0














You can prevent the default submit button behavior - submitting the form - with event.preventDefault();



 <script>
$(document).ready(function(){
$("#button").click(function(event){
// prevent the default submit button behaviour
event.preventDefault();
var postId=$("#postId").val();
var userId=$("#userId").val();
var postComm=$("#postComments").val();

$.ajax({
url:'../validate/inserPostComm.php',
method:'POST',
data:{
poId:postId,
usId:userId,
poco:postComm
},
success:function(data){
//alert(data);
}
});
});
});
</script>





share|improve this answer































    0














    another ajax i'm using but some issue is coming page is refreshing.



    <script>
    function inspire(x){
    var insPer =$("#insPer"+x).val();
    var insPos =$("#insPos"+x).val();


    $.ajax({
    url:'../validate/inspire.php',
    method:'POST',
    data:{
    u_id:insPer,
    p_id:insPos
    },
    success:function(data){
    //alert(data);
    }
    });
    }
    </script>


    this is html code



    <input type="hidden" id="insPer<?php echo $p_id; ?>" name="insPer" value="<?php echo $_SESSION["u_id"]; ?>"> 

    <input type="hidden" id="insPos<?php echo $p_id; ?>" name="insPos" value="<?php echo $p_id; ?>">

    <a href="#" onclick="inspire(<?php echo $p_id; ?>);">





    share|improve this answer

































      0














      Better do this






      $(document).ready(function(){
      $("form#comment").submit(function(e) {
      e.preventDefault();
      var formData = new FormData(this);
      // console.log(formData);
      $.ajax({
      url: '../validate/inserPostComm.php',
      type: 'POST',
      data: formData, //The Form data contain array (postId,userId,postComments)
      success: function (data) {
      // do something if success
      },
      error: function(xhr, ajaxOptions, thrownError) {
      //If error thrown here
      }
      });
      });
      });

      <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
      <form id="comment" method="post" enctype="multipart/form-data">
      <input type="hidden" id="postId" name="postId" value="...">
      <input type="hidden" id="userId" name="userId" value="...">
      <textarea placeholder="Post your comment" id="postComments" name="postComments"></textarea>
      <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
      </form>








      share|improve this answer
































        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        Easy fix: Add a preventDefault(). Notice the 'e' I added to your click function.



        <script>
        $(document).ready(function(){
        $("#button").click(function(e){
        e.preventDefault();

        var postId=$("#postId").val();
        var userId=$("#userId").val();
        var postComm=$("#postComments").val();

        $.ajax({
        url:'../validate/inserPostComm.php',
        method:'POST',
        data:{
        poId:postId,
        usId:userId,
        poco:postComm
        },
        success:function(data){
        //alert(data);
        }
        });
        });
        });
        </script>





        share|improve this answer
























        • This will work, also mention changing input type submit to button. :)

          – Smartpal
          Nov 16 '18 at 7:12











        • As a matter of practice, I do this with every button event listener whether it's submit or not. Just a little extra insurance.

          – Difster
          Nov 16 '18 at 7:18











        • It's Working and same like i'm using another ajax code that also same the pages is refreshing.

          – Jerad
          Nov 16 '18 at 7:18











        • @Difster yeah that's.

          – Smartpal
          Nov 16 '18 at 7:19
















        2














        Easy fix: Add a preventDefault(). Notice the 'e' I added to your click function.



        <script>
        $(document).ready(function(){
        $("#button").click(function(e){
        e.preventDefault();

        var postId=$("#postId").val();
        var userId=$("#userId").val();
        var postComm=$("#postComments").val();

        $.ajax({
        url:'../validate/inserPostComm.php',
        method:'POST',
        data:{
        poId:postId,
        usId:userId,
        poco:postComm
        },
        success:function(data){
        //alert(data);
        }
        });
        });
        });
        </script>





        share|improve this answer
























        • This will work, also mention changing input type submit to button. :)

          – Smartpal
          Nov 16 '18 at 7:12











        • As a matter of practice, I do this with every button event listener whether it's submit or not. Just a little extra insurance.

          – Difster
          Nov 16 '18 at 7:18











        • It's Working and same like i'm using another ajax code that also same the pages is refreshing.

          – Jerad
          Nov 16 '18 at 7:18











        • @Difster yeah that's.

          – Smartpal
          Nov 16 '18 at 7:19














        2












        2








        2







        Easy fix: Add a preventDefault(). Notice the 'e' I added to your click function.



        <script>
        $(document).ready(function(){
        $("#button").click(function(e){
        e.preventDefault();

        var postId=$("#postId").val();
        var userId=$("#userId").val();
        var postComm=$("#postComments").val();

        $.ajax({
        url:'../validate/inserPostComm.php',
        method:'POST',
        data:{
        poId:postId,
        usId:userId,
        poco:postComm
        },
        success:function(data){
        //alert(data);
        }
        });
        });
        });
        </script>





        share|improve this answer













        Easy fix: Add a preventDefault(). Notice the 'e' I added to your click function.



        <script>
        $(document).ready(function(){
        $("#button").click(function(e){
        e.preventDefault();

        var postId=$("#postId").val();
        var userId=$("#userId").val();
        var postComm=$("#postComments").val();

        $.ajax({
        url:'../validate/inserPostComm.php',
        method:'POST',
        data:{
        poId:postId,
        usId:userId,
        poco:postComm
        },
        success:function(data){
        //alert(data);
        }
        });
        });
        });
        </script>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 7:06









        DifsterDifster

        3,03811730




        3,03811730













        • This will work, also mention changing input type submit to button. :)

          – Smartpal
          Nov 16 '18 at 7:12











        • As a matter of practice, I do this with every button event listener whether it's submit or not. Just a little extra insurance.

          – Difster
          Nov 16 '18 at 7:18











        • It's Working and same like i'm using another ajax code that also same the pages is refreshing.

          – Jerad
          Nov 16 '18 at 7:18











        • @Difster yeah that's.

          – Smartpal
          Nov 16 '18 at 7:19



















        • This will work, also mention changing input type submit to button. :)

          – Smartpal
          Nov 16 '18 at 7:12











        • As a matter of practice, I do this with every button event listener whether it's submit or not. Just a little extra insurance.

          – Difster
          Nov 16 '18 at 7:18











        • It's Working and same like i'm using another ajax code that also same the pages is refreshing.

          – Jerad
          Nov 16 '18 at 7:18











        • @Difster yeah that's.

          – Smartpal
          Nov 16 '18 at 7:19

















        This will work, also mention changing input type submit to button. :)

        – Smartpal
        Nov 16 '18 at 7:12





        This will work, also mention changing input type submit to button. :)

        – Smartpal
        Nov 16 '18 at 7:12













        As a matter of practice, I do this with every button event listener whether it's submit or not. Just a little extra insurance.

        – Difster
        Nov 16 '18 at 7:18





        As a matter of practice, I do this with every button event listener whether it's submit or not. Just a little extra insurance.

        – Difster
        Nov 16 '18 at 7:18













        It's Working and same like i'm using another ajax code that also same the pages is refreshing.

        – Jerad
        Nov 16 '18 at 7:18





        It's Working and same like i'm using another ajax code that also same the pages is refreshing.

        – Jerad
        Nov 16 '18 at 7:18













        @Difster yeah that's.

        – Smartpal
        Nov 16 '18 at 7:19





        @Difster yeah that's.

        – Smartpal
        Nov 16 '18 at 7:19













        5














        You are facing it due to the button having input type “Submit”



        <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>


        Just change it to normal “button”



        <button type="button " id="button"><i class="fa fa-paper-plane"></i></button>





        share|improve this answer
























        • exactly type="submit" was the issue, vote up from me

          – TAHA SULTAN TEMURI
          Nov 16 '18 at 7:28
















        5














        You are facing it due to the button having input type “Submit”



        <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>


        Just change it to normal “button”



        <button type="button " id="button"><i class="fa fa-paper-plane"></i></button>





        share|improve this answer
























        • exactly type="submit" was the issue, vote up from me

          – TAHA SULTAN TEMURI
          Nov 16 '18 at 7:28














        5












        5








        5







        You are facing it due to the button having input type “Submit”



        <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>


        Just change it to normal “button”



        <button type="button " id="button"><i class="fa fa-paper-plane"></i></button>





        share|improve this answer













        You are facing it due to the button having input type “Submit”



        <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>


        Just change it to normal “button”



        <button type="button " id="button"><i class="fa fa-paper-plane"></i></button>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 7:09









        Sajjad AliSajjad Ali

        224210




        224210













        • exactly type="submit" was the issue, vote up from me

          – TAHA SULTAN TEMURI
          Nov 16 '18 at 7:28



















        • exactly type="submit" was the issue, vote up from me

          – TAHA SULTAN TEMURI
          Nov 16 '18 at 7:28

















        exactly type="submit" was the issue, vote up from me

        – TAHA SULTAN TEMURI
        Nov 16 '18 at 7:28





        exactly type="submit" was the issue, vote up from me

        – TAHA SULTAN TEMURI
        Nov 16 '18 at 7:28











        0














        You can prevent the default submit button behavior - submitting the form - with event.preventDefault();



         <script>
        $(document).ready(function(){
        $("#button").click(function(event){
        // prevent the default submit button behaviour
        event.preventDefault();
        var postId=$("#postId").val();
        var userId=$("#userId").val();
        var postComm=$("#postComments").val();

        $.ajax({
        url:'../validate/inserPostComm.php',
        method:'POST',
        data:{
        poId:postId,
        usId:userId,
        poco:postComm
        },
        success:function(data){
        //alert(data);
        }
        });
        });
        });
        </script>





        share|improve this answer




























          0














          You can prevent the default submit button behavior - submitting the form - with event.preventDefault();



           <script>
          $(document).ready(function(){
          $("#button").click(function(event){
          // prevent the default submit button behaviour
          event.preventDefault();
          var postId=$("#postId").val();
          var userId=$("#userId").val();
          var postComm=$("#postComments").val();

          $.ajax({
          url:'../validate/inserPostComm.php',
          method:'POST',
          data:{
          poId:postId,
          usId:userId,
          poco:postComm
          },
          success:function(data){
          //alert(data);
          }
          });
          });
          });
          </script>





          share|improve this answer


























            0












            0








            0







            You can prevent the default submit button behavior - submitting the form - with event.preventDefault();



             <script>
            $(document).ready(function(){
            $("#button").click(function(event){
            // prevent the default submit button behaviour
            event.preventDefault();
            var postId=$("#postId").val();
            var userId=$("#userId").val();
            var postComm=$("#postComments").val();

            $.ajax({
            url:'../validate/inserPostComm.php',
            method:'POST',
            data:{
            poId:postId,
            usId:userId,
            poco:postComm
            },
            success:function(data){
            //alert(data);
            }
            });
            });
            });
            </script>





            share|improve this answer













            You can prevent the default submit button behavior - submitting the form - with event.preventDefault();



             <script>
            $(document).ready(function(){
            $("#button").click(function(event){
            // prevent the default submit button behaviour
            event.preventDefault();
            var postId=$("#postId").val();
            var userId=$("#userId").val();
            var postComm=$("#postComments").val();

            $.ajax({
            url:'../validate/inserPostComm.php',
            method:'POST',
            data:{
            poId:postId,
            usId:userId,
            poco:postComm
            },
            success:function(data){
            //alert(data);
            }
            });
            });
            });
            </script>






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 16 '18 at 7:34









            Razvan ZamfirRazvan Zamfir

            1,10411360




            1,10411360























                0














                another ajax i'm using but some issue is coming page is refreshing.



                <script>
                function inspire(x){
                var insPer =$("#insPer"+x).val();
                var insPos =$("#insPos"+x).val();


                $.ajax({
                url:'../validate/inspire.php',
                method:'POST',
                data:{
                u_id:insPer,
                p_id:insPos
                },
                success:function(data){
                //alert(data);
                }
                });
                }
                </script>


                this is html code



                <input type="hidden" id="insPer<?php echo $p_id; ?>" name="insPer" value="<?php echo $_SESSION["u_id"]; ?>"> 

                <input type="hidden" id="insPos<?php echo $p_id; ?>" name="insPos" value="<?php echo $p_id; ?>">

                <a href="#" onclick="inspire(<?php echo $p_id; ?>);">





                share|improve this answer






























                  0














                  another ajax i'm using but some issue is coming page is refreshing.



                  <script>
                  function inspire(x){
                  var insPer =$("#insPer"+x).val();
                  var insPos =$("#insPos"+x).val();


                  $.ajax({
                  url:'../validate/inspire.php',
                  method:'POST',
                  data:{
                  u_id:insPer,
                  p_id:insPos
                  },
                  success:function(data){
                  //alert(data);
                  }
                  });
                  }
                  </script>


                  this is html code



                  <input type="hidden" id="insPer<?php echo $p_id; ?>" name="insPer" value="<?php echo $_SESSION["u_id"]; ?>"> 

                  <input type="hidden" id="insPos<?php echo $p_id; ?>" name="insPos" value="<?php echo $p_id; ?>">

                  <a href="#" onclick="inspire(<?php echo $p_id; ?>);">





                  share|improve this answer




























                    0












                    0








                    0







                    another ajax i'm using but some issue is coming page is refreshing.



                    <script>
                    function inspire(x){
                    var insPer =$("#insPer"+x).val();
                    var insPos =$("#insPos"+x).val();


                    $.ajax({
                    url:'../validate/inspire.php',
                    method:'POST',
                    data:{
                    u_id:insPer,
                    p_id:insPos
                    },
                    success:function(data){
                    //alert(data);
                    }
                    });
                    }
                    </script>


                    this is html code



                    <input type="hidden" id="insPer<?php echo $p_id; ?>" name="insPer" value="<?php echo $_SESSION["u_id"]; ?>"> 

                    <input type="hidden" id="insPos<?php echo $p_id; ?>" name="insPos" value="<?php echo $p_id; ?>">

                    <a href="#" onclick="inspire(<?php echo $p_id; ?>);">





                    share|improve this answer















                    another ajax i'm using but some issue is coming page is refreshing.



                    <script>
                    function inspire(x){
                    var insPer =$("#insPer"+x).val();
                    var insPos =$("#insPos"+x).val();


                    $.ajax({
                    url:'../validate/inspire.php',
                    method:'POST',
                    data:{
                    u_id:insPer,
                    p_id:insPos
                    },
                    success:function(data){
                    //alert(data);
                    }
                    });
                    }
                    </script>


                    this is html code



                    <input type="hidden" id="insPer<?php echo $p_id; ?>" name="insPer" value="<?php echo $_SESSION["u_id"]; ?>"> 

                    <input type="hidden" id="insPos<?php echo $p_id; ?>" name="insPos" value="<?php echo $p_id; ?>">

                    <a href="#" onclick="inspire(<?php echo $p_id; ?>);">






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Nov 16 '18 at 10:10









                    Vishnu

                    4,51613160




                    4,51613160










                    answered Nov 16 '18 at 7:28









                    JeradJerad

                    829




                    829























                        0














                        Better do this






                        $(document).ready(function(){
                        $("form#comment").submit(function(e) {
                        e.preventDefault();
                        var formData = new FormData(this);
                        // console.log(formData);
                        $.ajax({
                        url: '../validate/inserPostComm.php',
                        type: 'POST',
                        data: formData, //The Form data contain array (postId,userId,postComments)
                        success: function (data) {
                        // do something if success
                        },
                        error: function(xhr, ajaxOptions, thrownError) {
                        //If error thrown here
                        }
                        });
                        });
                        });

                        <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                        <form id="comment" method="post" enctype="multipart/form-data">
                        <input type="hidden" id="postId" name="postId" value="...">
                        <input type="hidden" id="userId" name="userId" value="...">
                        <textarea placeholder="Post your comment" id="postComments" name="postComments"></textarea>
                        <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
                        </form>








                        share|improve this answer






























                          0














                          Better do this






                          $(document).ready(function(){
                          $("form#comment").submit(function(e) {
                          e.preventDefault();
                          var formData = new FormData(this);
                          // console.log(formData);
                          $.ajax({
                          url: '../validate/inserPostComm.php',
                          type: 'POST',
                          data: formData, //The Form data contain array (postId,userId,postComments)
                          success: function (data) {
                          // do something if success
                          },
                          error: function(xhr, ajaxOptions, thrownError) {
                          //If error thrown here
                          }
                          });
                          });
                          });

                          <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                          <form id="comment" method="post" enctype="multipart/form-data">
                          <input type="hidden" id="postId" name="postId" value="...">
                          <input type="hidden" id="userId" name="userId" value="...">
                          <textarea placeholder="Post your comment" id="postComments" name="postComments"></textarea>
                          <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
                          </form>








                          share|improve this answer




























                            0












                            0








                            0







                            Better do this






                            $(document).ready(function(){
                            $("form#comment").submit(function(e) {
                            e.preventDefault();
                            var formData = new FormData(this);
                            // console.log(formData);
                            $.ajax({
                            url: '../validate/inserPostComm.php',
                            type: 'POST',
                            data: formData, //The Form data contain array (postId,userId,postComments)
                            success: function (data) {
                            // do something if success
                            },
                            error: function(xhr, ajaxOptions, thrownError) {
                            //If error thrown here
                            }
                            });
                            });
                            });

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                            <form id="comment" method="post" enctype="multipart/form-data">
                            <input type="hidden" id="postId" name="postId" value="...">
                            <input type="hidden" id="userId" name="userId" value="...">
                            <textarea placeholder="Post your comment" id="postComments" name="postComments"></textarea>
                            <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
                            </form>








                            share|improve this answer















                            Better do this






                            $(document).ready(function(){
                            $("form#comment").submit(function(e) {
                            e.preventDefault();
                            var formData = new FormData(this);
                            // console.log(formData);
                            $.ajax({
                            url: '../validate/inserPostComm.php',
                            type: 'POST',
                            data: formData, //The Form data contain array (postId,userId,postComments)
                            success: function (data) {
                            // do something if success
                            },
                            error: function(xhr, ajaxOptions, thrownError) {
                            //If error thrown here
                            }
                            });
                            });
                            });

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                            <form id="comment" method="post" enctype="multipart/form-data">
                            <input type="hidden" id="postId" name="postId" value="...">
                            <input type="hidden" id="userId" name="userId" value="...">
                            <textarea placeholder="Post your comment" id="postComments" name="postComments"></textarea>
                            <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
                            </form>








                            $(document).ready(function(){
                            $("form#comment").submit(function(e) {
                            e.preventDefault();
                            var formData = new FormData(this);
                            // console.log(formData);
                            $.ajax({
                            url: '../validate/inserPostComm.php',
                            type: 'POST',
                            data: formData, //The Form data contain array (postId,userId,postComments)
                            success: function (data) {
                            // do something if success
                            },
                            error: function(xhr, ajaxOptions, thrownError) {
                            //If error thrown here
                            }
                            });
                            });
                            });

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                            <form id="comment" method="post" enctype="multipart/form-data">
                            <input type="hidden" id="postId" name="postId" value="...">
                            <input type="hidden" id="userId" name="userId" value="...">
                            <textarea placeholder="Post your comment" id="postComments" name="postComments"></textarea>
                            <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
                            </form>





                            $(document).ready(function(){
                            $("form#comment").submit(function(e) {
                            e.preventDefault();
                            var formData = new FormData(this);
                            // console.log(formData);
                            $.ajax({
                            url: '../validate/inserPostComm.php',
                            type: 'POST',
                            data: formData, //The Form data contain array (postId,userId,postComments)
                            success: function (data) {
                            // do something if success
                            },
                            error: function(xhr, ajaxOptions, thrownError) {
                            //If error thrown here
                            }
                            });
                            });
                            });

                            <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
                            <form id="comment" method="post" enctype="multipart/form-data">
                            <input type="hidden" id="postId" name="postId" value="...">
                            <input type="hidden" id="userId" name="userId" value="...">
                            <textarea placeholder="Post your comment" id="postComments" name="postComments"></textarea>
                            <button type="submit" id="button"><i class="fa fa-paper-plane"></i></button>
                            </form>






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Dec 13 '18 at 15:40

























                            answered Nov 16 '18 at 8:07









                            Thomas JerikoThomas Jeriko

                            469




                            469















                                Popular posts from this blog

                                List item for chat from Array inside array React Native

                                Thiostrepton

                                Caerphilly