Last active
March 26, 2016 08:15
-
-
Save omurphy27/c2a6b498d6d08301cab2 to your computer and use it in GitHub Desktop.
Jquery Ajax Form Submit Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$formUserchange.on('submit', function(e) { | |
e.preventDefault(); | |
var $newUser = $(this).find('input[name=new-username]').val(), | |
$url = $(this).attr('action'), | |
$method = $(this).attr('method'), | |
$data = { | |
'new-username' : $newUser | |
}; | |
$.ajax({ | |
url: $url, | |
type:$method, | |
data: $data, | |
// data: $(this).serialize(), - this is another way to pass in the data | |
dataType: 'JSON', | |
error: function (xhr, ajaxOptions, thrownError) { | |
console.log(xhr.status); | |
console.log(xhr.responseText); | |
console.log(thrownError); | |
} | |
}).done(function(response) { | |
if (response.hasOwnProperty('success')) { | |
window.location.reload(); | |
} else { | |
alert(response); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment