-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddComment.js
More file actions
43 lines (40 loc) · 1.24 KB
/
Copy pathaddComment.js
File metadata and controls
43 lines (40 loc) · 1.24 KB
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(){
$("#form1").submit(function(event) {
var $form = $(this);
// let's select and cache all the fields
var $inputs = $form.find("input, select, button, textarea");
// serialize the data in the form
var serializedData = $form.serialize();
// let's disable the inputs for the duration of the ajax request
$inputs.attr("disabled", "disabled");
$.ajax({
type: "POST",
url: "addComment.php",
data: serializedData,
// callback handler that will be called on success
success: function(response, textStatus, jqXHR){
// log a message to the console
console.log("Comment submitted successfully");
$("input#CommentText").val('');
},
// callback handler that will be called on error
error: function(jqXHR, textStatus, errorThrown){
// log the error to the console
console.log(
"The following error occured: "+
textStatus, errorThrown
);
},
// callback handler that will be called on completion
// which means, either on success or error
complete: function(){
// enable the inputs
$inputs.removeAttr("disabled");
$("input#CommentText").focus();
}
});
// prevent default posting of form
//event.preventDefault();
return false;
});
});