最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

javascript - ajax page refresh on form submit success - Stack Overflow

matteradmin7PV0评论

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
Add a ment  | 

3 Answers 3

Reset to default 1

Use 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

Post a comment

comment list (0)

  1. No comments so far