【问题标题】:How to complete reset a page in jQuery Mobile after submitting a form提交表单后如何在 jQuery Mobile 中完成重置页面
【发布时间】:2013-07-16 16:01:07
【问题描述】:

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

这是我在 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一样。

【问题讨论】:

    标签: jquery forms mobile submit reset


    【解决方案1】:

    尝试使用此功能 -

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

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

    Reload the Same Page Without Blinking on jQuery Mobile

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

    【讨论】:

    • 该函数不起作用,但使用 $(#form)[0].reset(); 将值重置为空;做了。
    猜你喜欢
    • 2014-07-12
    • 2023-04-04
    • 1970-01-01
    • 2015-05-28
    • 1970-01-01
    • 2018-01-19
    • 1970-01-01
    • 2020-09-13
    • 1970-01-01
    相关资源
    最近更新 更多