-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
91 lines (81 loc) · 2.76 KB
/
index.html
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="icon" href="favicon.ico"/>
<script src="http://code.jquery.com/jquery-2.1.0.js"></script>
<title>Document</title>
<script>
$(document).ready(function () {
// variable to hold request
var request;
// bind to the submit event of our form
$("#foo").submit(function (event) {
// abort any pending request
if (request) {
request.abort();
}
// setup some local variables
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
// Note: we disable elements AFTER the form data has been serialized.
// Disabled form elements will not be serialized.
$inputs.prop("disabled", true);
$('#result').text('Sending data...');
// fire off the request to /form.php
request = $.ajax({
url : "https://script.google.com/macros/s/AKfycbwy_70uxGw1hsNbgXN0K9Lnjt2vFriM14qfdQmE0dIyNq6Vbjo/exec",
type : "post",
data : serializedData
});
// callback handler that will be called on success
request.done(function (response, textStatus, jqXHR) {
// log a message to the console
if(response.result == "success") {
$('#result').text('Data sent');
} else {
$('#result').text('Got an error: ' + response.error);
}
});
// callback handler that will be called on failure
request.fail(function (jqXHR, textStatus, errorThrown) {
// log the error to the console
console.error(
"The following error occured: " +
textStatus, errorThrown
);
$('#result').text('Got an error: ' + textStatus);
});
// callback handler that will be called regardless
// if the request failed or succeeded
request.always(function () {
// reenable the inputs
$inputs.prop("disabled", false);
});
// prevent default posting of form
event.preventDefault();
});
});
</script>
</head>
<body>
<h1>Send data to google</h1>
<form id="foo">
<label for="name">Name</label>
<input type="text" name="name" id="name" required="required"/>
<br />
<label for="email">Email</label>
<input type="email" name="email" id="email" required="required"/>
<br />
<label for="url">Portfolio URL</label>
<input type="url" name="url" id="url"/>
<br />
<button type="submit">Absenden</button>
</form>
<p id="result"></p>
</body>
</html>