Inserting through AJAX page is refreshing [duplicate]
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>
javascript php jquery ajax
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.
add a comment |
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>
javascript php jquery ajax
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 fromsubmittobutton
– 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
add a comment |
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>
javascript php jquery ajax
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
javascript php jquery ajax
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 fromsubmittobutton
– 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
add a comment |
5
Change the type of button fromsubmittobutton
– 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
add a comment |
5 Answers
5
active
oldest
votes
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>
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
add a comment |
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>
exactly type="submit" was the issue, vote up from me
– TAHA SULTAN TEMURI
Nov 16 '18 at 7:28
add a comment |
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>
add a comment |
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; ?>);">
add a comment |
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>add a comment |
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
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>
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
add a comment |
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>
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
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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>
exactly type="submit" was the issue, vote up from me
– TAHA SULTAN TEMURI
Nov 16 '18 at 7:28
add a comment |
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>
exactly type="submit" was the issue, vote up from me
– TAHA SULTAN TEMURI
Nov 16 '18 at 7:28
add a comment |
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>
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>
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
add a comment |
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
add a comment |
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>
add a comment |
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>
add a comment |
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>
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>
answered Nov 16 '18 at 7:34
Razvan ZamfirRazvan Zamfir
1,10411360
1,10411360
add a comment |
add a comment |
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; ?>);">
add a comment |
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; ?>);">
add a comment |
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; ?>);">
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; ?>);">
edited Nov 16 '18 at 10:10
Vishnu
4,51613160
4,51613160
answered Nov 16 '18 at 7:28
JeradJerad
829
829
add a comment |
add a comment |
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>add a comment |
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>add a comment |
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>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>edited Dec 13 '18 at 15:40
answered Nov 16 '18 at 8:07
Thomas JerikoThomas Jeriko
469
469
add a comment |
add a comment |
5
Change the type of button from
submittobutton– 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