10 - Post Data with JavaScript XMLHttpRequest Method - JSON APIs and AJAX - freeCodeCamp Tutorial

preview_player
Показать описание
At 10:12 put a capital S in readyState and you should be gucci!
We can also post data using the JavaScript XMLHttpRequest. This time, we open it with a 'POST' attribute, set some headers specifying the content-type, and send it. We can register functions with the onreadystatechange to run code once we get a response.

Concepts:

An EventHandler that is called whenever the readyState attribute changes.

The XMLHttpRequest method setRequestHeader() sets the value of an HTTP request header. When using setRequestHeader(), you must call it after calling open(), but before calling send(). If this method is called several times with the same header, the values are merged into one single request header.

JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate.

parse()
The JSON.parse() method parses a JSON string, constructing the JavaScript value or object described by the string.

stringify()
The JSON.stringify() method converts a JavaScript object or value to a JSON string, optionally replacing values if a replacer function is specified or optionally including only the specified properties if a replacer array is specified.

XMLHttpRequest
XMLHttpRequest (XHR) objects are used to interact with servers. You can retrieve data from a URL without having to do a full page refresh. This enables a Web page to update just part of a page without disrupting what the user is doing. XMLHttpRequest is used heavily in AJAX programming.

The XMLHttpRequest method open() initializes a newly-created request, or re-initializes an existing one.

The XMLHttpRequest method send() sends the request to the server. If the request is asynchronous (which is the default), this method returns as soon as the request is sent and the result is delivered using events. If the request is synchronous, this method doesn't return until the response has arrived.
-————————————————————————————————————-
JSON (JavaScript Object Notation) is an open standard file format, and data interchange format, that uses human-readable text to store and transmit data objects consisting of attribute–value pairs and array data types.

Ajax is a set of web development techniques using many web technologies on the client side to create asynchronous web applications. With Ajax, web applications can send and retrieve data from a server asynchronously without interfering with the display and behavior of the existing page.

freeCodeCamp (also referred to as “Free Code Camp”) is a non-profit organization that consists of an interactive learning web platform, an online community forum, chat rooms, online publications and local organizations that intend to make learning web development accessible to anyone. Beginning with tutorials that introduce students to HTML, CSS and JavaScript, students progress to project assignments that they complete either alone or in pairs. Upon completion of all project tasks, students are partnered with other nonprofits to build web applications, giving the students practical development experience.

Thanks for Watching!
Рекомендации по теме
Комментарии
Автор

Hey, I do exactly what you did. but I get a 405 method not allowed error in my console. what should I do?

doctorbrad
welcome to shbcf.ru