Ajax post方法发布数据但在刷新页面时收到警告消息

时间:2013-03-04 19:51:47

标签: ajax jquery

我使用下面的ajax发布

$('#myFormId').on('submit', function() {

    var form_data = {
        csrfsecurity: $("input[name=csrfsecurity]").val(),
        post_text: $('#post_text').val()    
    };

    $.ajax({
        url: "<?php echo site_url('/post_status'); ?>",
        type: 'POST',
        data: form_data,
        success: function(response){
            $(".home_user_feeds").html("markUpCreatedUsingResponseFromServer");
        }
    });
    return false;
});

当我发布内容并刷新页面时,浏览器会显示以下警告。

Confirm Form Resubmission

The page that you're looking for used information that you entred. Returning to that page might cause any action you took to be repeated.

如何摆脱它。

1 个答案:

答案 0 :(得分:0)

首先尝试阻止默认表单事件:

$('#myFormId').on('submit', function(e) {

    e.preventDefault();

    var form_data = {
        csrfsecurity: $("input[name=csrfsecurity]").val(),
        post_text: $('#post_text').val()    
    };

    $.ajax({
        url: "<?php echo site_url('/post_status'); ?>",
        type: 'POST',
        data: form_data,
        success: function(response){
            $(".home_user_feeds").html("markUpCreatedUsingResponseFromServer");
        }
    });
    return false;
});