1

This is a trivial question but I can't find the answer.

This is the code I use to submit my form in 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
}); 

So what do put in the success function? What I want to achieve is that the user stays on the form page, but that the page is basically refreshed, as if someone pushed F5.

MacBryce
  • 133
  • 1
  • 3
  • 14

1 Answers1

0

Try using this function -

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

There are some other solutions to this, I found them here on stackoverflow - jQuery Mobile Page refresh mechanism

Reload the Same Page Without Blinking on jQuery Mobile

Have you considered manually setting your form values back to empty on the page? This may be a more optimal solution.

Community
  • 1
  • 1
Ross
  • 3,335
  • 1
  • 19
  • 18