-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathformSubmitAjax.js
44 lines (40 loc) · 1.4 KB
/
formSubmitAjax.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$(document).ready(function() {
$('.formContainer input[type=submit]').click(function() {
var submitType = $(this).attr("value");
$('.formContainer ' + '#' + submitType + ' form').submit(function(e) {
var postData = $(this).serializeArray();
var formURL = $(this).attr("action");
postData.push({ name: "submit", value: submitType });
$.ajax({
url : formURL,
type: "POST",
data : postData,
success:function(html)
{
//window.alert(html);
$('#msg').html(html);
$('#' + submitType + ' input[type="text"]').val("");
$(document).trigger("formSubmitted");
$('select').change();
},
error: function(html)
{
window.alert("failed");
}
});
e.preventDefault(); //don't refresh the page
e.unbind();
});
});
$(document).on("formSubmitted", function () {
$.ajax({
type: 'POST',
url: 'ajaxSubmit.php',
data: 'getUniversities=true',
success: function (html) {
$('.selectedUniversity').html(html).change();
$('.formContainer select').change();
}
});
});
});