-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest-form
49 lines (36 loc) · 970 Bytes
/
test-form
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
44
45
46
47
48
49
<!DOCTYPE html>
<html>
<head>
<title>Ajax Test</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
<script>
$(document).ready(function()
{
$('#greetingform').submit(function(e)
{
// don't submit the form, please
e.preventDefault();
// print something to the console
console.log('We are printing something to the console');
// make an ajax call
$.ajax({
method: "POST",
url: "greeting.php",
data: $('#greetingform').serialize(),
dataType: "json"
}).done(function( json ) {
$('#message').html("Hello " + json.firstname);
});
});
});
</script>
</head>
<body>
<h1 id="message"></h1>
<form id="greetingform">
<label for="firstname">What is your firstname?</label><br />
<input name="firstname" type="text" />
<input name="submit" type="submit" value="Send" />
</form>
</body>
</html>