1

这是一个微不足道的问题,但我找不到答案。

这是我用来在 jQuery mobile 中提交表单的代码

$(document).on('click', '#submit', function() { // catch the form's submit event
    // Send data to server through ajax call
    // action is functionality we want to call and output - JSON is our data
    $.ajax({
        url: 'includes/db/ajax_insert_completed_quests.php',
        data: $('#form').serialize(),
        type: 'get',                   
        async: true,
        beforeSend: function() {
            // This callback function will trigger before data is sent
            $.mobile.showPageLoadingMsg(true); // This will show ajax spinner
        },
        complete: function() {
            // This callback function will trigger on data sent/received complete
            $.mobile.hidePageLoadingMsg(); // This will hide ajax spinner
        },
        success: function (result) {

        },
        error: function (request,error) {
            // This callback function will trigger on unsuccessful action                
            alert('Network error has occurred please try again!');
        }
    });                         
    return false; // cancel original event to prevent form submitting
}); 

那么在success函数里放什么?我想要实现的是用户停留在表单页面,但是页面基本刷新了,好像有人按了F5。

4

1 回答 1

0

尝试使用此功能 -

function refreshPage() {
    jQuery.mobile.changePage(window.location.href, {
        allowSamePageTransition: true,
        transition: 'none',
        reloadPage: true
    });
}

还有一些其他的解决方案,我在stackoverflow上找到了它们 - jQuery Mobile Page refresh mechanism

在 jQuery Mobile 上重新加载同一页面而不闪烁

您是否考虑过在页面上手动将表单值设置回空?这可能是一个更优化的解决方案。

于 2013-07-16T16:09:35.020 回答