Java Reference
In-Depth Information
console.log(xhr.responseText);
}
};
xhr.send(hero);
}
Now if you open up the hero.htm file, fill in some form details about a superhero and sub-
mit it, you should receive a response from the Reqres website in the console similar to the
one that follows. It indicates that the data has been saved as the returned object with the ex-
tra properties id and createdAt that have been added by a database (in reality, the data
hasn't been saved, and these properties have just been added for demonstration purposes):
<< "{"name":"Superman","realName":"Clarke
Kent","powers":["Flight",
"Strength","Super
Speed"],"type":"Hero","city":"Metropolis",
"origin":"Born as Kal-El on the planet Krypton, before
being ...",
"age":"28","id":"242","createdAt":"2014-11-02T15:38:02.116Z"}"
Most forms will have an action attribute that specifies the URL to use if the form is sent
without using Ajax. It will also have a method attribute that will specify the HTTP verb to
use. These methods are available as properties of the form object, so the open() method
can be generalized to work for any form as:
xhr.open(form.method, form.action, true);
Search WWH ::




Custom Search