i am using this ajax code to submit a form
<script type="text/javascript">
$(document).ready(function(){
$("#ticketupdate_message").hide();
$("#ticketupdate_please_wait_box").hide();
$("#ticket_update").submit(function(e){
$("#ticketupdate_message").hide();
$("#ticketupdate_please_wait_box").show();
e.preventDefault();
dataString=$("#ticket_update").serialize();
$.ajax({
type: "POST",
url: "reviewtickets_history.php?seq=<?php echo $_GET["seq"]; ?>",
cache: false,
data: dataString,
success: function(res){
$("#ticketupdate_please_wait_box").hide();
$("#ticketupdate_message").html(res);
$('#ticketupdate_message').fadeIn('slow');
$('.overlay').fadeOut();
if(res.indexOf("success")!=-1)
{
window.location.href = res.substr(8);
}
else
{
$("#ticket_update")[0].reset();
}
}
});
});
});
</script>
how can i add a page refresh if it was successful?
i am using this ajax code to submit a form
<script type="text/javascript">
$(document).ready(function(){
$("#ticketupdate_message").hide();
$("#ticketupdate_please_wait_box").hide();
$("#ticket_update").submit(function(e){
$("#ticketupdate_message").hide();
$("#ticketupdate_please_wait_box").show();
e.preventDefault();
dataString=$("#ticket_update").serialize();
$.ajax({
type: "POST",
url: "reviewtickets_history.php?seq=<?php echo $_GET["seq"]; ?>",
cache: false,
data: dataString,
success: function(res){
$("#ticketupdate_please_wait_box").hide();
$("#ticketupdate_message").html(res);
$('#ticketupdate_message').fadeIn('slow');
$('.overlay').fadeOut();
if(res.indexOf("success")!=-1)
{
window.location.href = res.substr(8);
}
else
{
$("#ticket_update")[0].reset();
}
}
});
});
});
</script>
how can i add a page refresh if it was successful?
Share Improve this question asked Jan 9, 2014 at 16:35 charliecharlie 1,3847 gold badges38 silver badges77 bronze badges 3-
If you reload the page, what's the point of all the other actions you have in the
success
callback? – Barmar Commented Jan 9, 2014 at 16:37 - the other actions are not going to be there , i will remove them when i manage to make the page reload – charlie Commented Jan 9, 2014 at 16:37
- Refreshing the page will nuke any changes you did to the page inside the success handler... – Marc B Commented Jan 9, 2014 at 16:38
3 Answers
Reset to default 1Use location.reload();
to reload the page
if(res.indexOf("success")!=-1)
{
location.reload();
}
Refer : MDN
you can use location.reload();
Using location.reload()
https://developer.mozilla/en-US/docs/Web/API/Location.reload:
if(res.indexOf("success")!=-1)
{
location.reload();
}
If you want to override cache, add a true
parameter: location.reload(true);
Cheers