最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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

发布评论

评论列表(0)

  1. 暂无评论