Carlcox89
Carlcox89

Reputation: 613

jQuery mobile get without page redirection

I have the following:

<div data-role='popup' id='popupSchedule' data-theme='a' class='ui-corner-all'>
    <form id='schedule'>
        <div style='padding:10px 20px;'>
            <div data-role='fieldcontain'>
                <label for='masterOn'>Activate:</label>
                <input type='time' name='masterOn' id='masterOn' value='' data-mini='true' data-theme='a'>
                <label for='masterOff'>Deactivate:</label>
                <input type='time' name='masterOff' id='masteroff' value='' data-mini='true' data-theme='a'>
                <input type='submit' id='setSchedule' class='ui-btn ui-corner-all ui-shadow ui-btn-b ui-btn-icon-left ui-icon-check' value='Confirm'>
            </div>
        </div>
    </form>
</div>

that is a popup in jQuery... What I want to do is a GET with the elements (masterOn, masterOff ) values when the user clicks the submit button, like:

"$('#schedule').submit(function(event) { "
    "$.get('/cmd', masterOn value ..... masterOff value ...);

"});"

Then close the popup without page redirection (because I have a multi-page implementation and I need it to not redirect).

Upvotes: 0

Views: 79

Answers (1)

Batu.Khan
Batu.Khan

Reputation: 3065

$('#schedule').submit(function(event) { 
  $.get("/cmd", { masterOn : $("#masterOn").val(), masterOff : $("#masterOff").val() } )
   .done(function( data ) {
     // do your stuff with data
   })
   .fail(function() {
     // do your stuff if get fails
   });
   return false; // this is what you need to do to prevent page redirection
});

Upvotes: 1

Related Questions