Asychronicity in JavaScript
[Pages:33]Asynchrony in JavaScript
Alper Sarikaya (@yelperalp)
CS 638 JavaScript & Web Programming November 17th, 2015
Asynchrony in JavaScript
How we handle it in JavaScript (and jQuery, D3, etc.)
Requesting data in JavaScript (and jQuery, D3, etc.)
Event Handling (and jQuery, D3, etc.)
Reactive Programming
WebSockets/binary data/WebGL
WebWorkers
-
JavaScript is single-threaded!
This means:
Asynchronous events can return and interrupt
Long processing work can block interrupts from occurring (page appears to hang)
Only one thing can be done at a time
(except if you use WebWorkers; more later)
Handling Asynchronicity
Want to (without reloading page):
Get data from datastore on the webserver Update state on webserver based on user action Post a message, record a vote for others to see Retrieve some video/binary data to display to client
Handling Asynchronicity
Make an XmlHttpRequest (XHR) Ajax programming model
Asynchronous JavaScript and XML
var xhr = new XMLHttpRequest(); xhr.open('GET', 'DoSomething.php', true); xhr.responseType = 'json';
xhr.addEventListener('load', function() { if (xhr.status == 200) { loadBinaryData(xhr.response); } else { console.warning("failed to load (status: %d)", xhr.status); console.trace(); }
});
xhr.send(null);
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- f data accessing structured data made easy
- owasp top ten defenses
- asychronicity in javascript
- javascript part 2
- 1 csc 443 web programming
- module 5 javascript ajax and jquery
- procedure to request a json file or an xml file in the
- jquery json ajax
- convert form data to json using jquery
- javascript jquery and ajax
Related searches
- javascript update item in array
- javascript replace item in array
- javascript find object in list
- javascript count elements in array
- javascript count char in string
- javascript find string in array
- javascript if string in array
- javascript find minimum in array
- javascript minimum value in array
- javascript find max in array
- objects in javascript examples
- javascript get time in format