tailieunhanh - Học JavaScript qua ví dụ part 94

Ajax và JSON JSON là gì? JSON, JavaScript Object Notation, như Ajax, không phải là một ngôn ngữ lập trình, nhưng tập hợp con của JavaScript. Đây là một văn bản dựa trên | 834 Chapter 18 An Introduction to Ajax with JSON EXAMPLE continued p input type button value submit onClick ajaxFunction form div id message class divStyle div p body html EXPLANATION 1 When the XMLHttpRequest object is initialized the open method takes two parameters in this example the HTTP method is POST and the URL is the name of the server-side PHP script that will process form input sent by the server. The default is asynchronous true specified as a third parameter. 2 With the POST method another header is sent to the server specifying the Content-type . 3 Instead of sending the query string as a set of parameters to the open method they are sent to the server by the send method. 4 This is where the HTML form starts. There are no attributes. Ajax and JSON What is JSON JSON JavaScript Object Notation like Ajax is not a programming language but a subset of JavaScript. It is a text-based format that provides an easy way to exchange and parse data over a network. Although JSON was originally tied to JavaScript it is language independent and is now used by Ruby PHP C Python Java Perl and so on. The JSON format is often used for serialization and transmitting structured data with Ajax. If you recall in Example when using Ajax and XML there was a lot involved. First you had to understand how XML structures its data and next how to create the XML DOM object when the server returns the contents of the XML file and finally how to use the DOM to parse the data. JSON offers a nice alternative to using XML. Instead JSON represents data as an array or associative array JavaScript object and any language that supports this representation of data can use it. Most modern browsers are providing an implementation of native JSON so that you can use parse and string methods provided by the browser to handle JSON data. For example Firefox Internet Explorer 8 Google Chrome and Apple Safari have introduced support for native JSON and the ECMAScript Fifth Edition

TỪ KHÓA LIÊN QUAN