OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 /** | |
6 * Keypress handler for the textarea. Sends the textarea value | |
7 * to the HTTP server when "Enter" key is pressed. | |
8 * @param {Event} e The keypress event. | |
9 */ | |
10 function handleTextareaKeyPressed(event) { | |
11 // If the "Enter" key is pressed | |
12 // then process the text in the textarea. | |
Jamie
2014/03/04 21:40:35
Nit: This comment is wrapped in an odd place.
chaitali
2014/03/05 22:02:22
Done.
| |
13 if (event.which == 13) { | |
14 var testTextVal = document.getElementById('testtext').value; | |
15 var postParams = 'text=' + testTextVal; | |
16 | |
17 var request = new XMLHttpRequest(); | |
18 request.open('POST', '/keytest/test', true); | |
Jamie
2014/03/04 21:40:35
Can we use a relative URL here too?
chaitali
2014/03/05 22:02:22
Same comment. Removed the initial / if thats what
| |
19 request.setRequestHeader( | |
20 'Content-type', 'application/x-www-form-urlencoded'); | |
21 | |
22 request.onreadystatechange = function() { | |
23 if(request.readyState == 4 && request.status == 200) { | |
24 console.log('Sent POST request to server.'); | |
25 } | |
26 }; | |
27 | |
28 request.onerror = function() { | |
29 console.log('Request failed'); | |
30 }; | |
31 | |
32 request.send(postParams); | |
33 } | |
34 }; | |
35 | |
36 window.addEventListener('load', function(){ | |
37 document.getElementById('testtext').addEventListener( | |
38 'keypress', | |
39 handleTextareaKeyPressed, | |
40 false); | |
41 }); | |
Jamie
2014/03/04 21:40:35
Missing 'false'.
chaitali
2014/03/05 22:02:22
Done.
| |
42 | |
OLD | NEW |