TAILIEUCHUNG - Học JavaScript qua ví dụ part 95

Đưa It All Cùng với JSON Trong các tập tiếp theo của ví dụ, chúng ta sẽ tạo một tập tin văn bản JSON, với cơ cấu của một đối tượng JavaScript (trên thực tế, bất kỳ chương trình sử dụng băm hay mảng kết hợp có thể đọc được file này), sử dụng một chương trình Ajax để yêu cầu các tập tin và sau khi nhận được một phản hồi từ máy chủ, | Ajax and JSON 839 EXAMPLE continued 3. Output after the eval . Name Joe shmoe Ĩ Salary -ĩ Age 35 Married true Putting It All Together with JSON In the next set of examples we will create a JSON text file with the structure of a JavaScript object in fact any program employing hashes or associative arrays could read this file use an Ajax program to request the file and after getting a response from the server read and parse the JSON data with JavaScript s eval function then place the parsed data in a div container and display it shown in Figure . The JSON File EXAMPLE 1 make Honda Civic year 2006 price 18000 2 owner name Henry Lee cellphone 222-222-2222 3 address street 10 Main city San Francisco state CA dealer SF Honda 4 EXPLANATION 1 This is a JSON object consisting of properties and their values key value pairs . 2 The owner property has nested properties. If the object is named car then to get the cell phone number for the owner the dot notation is used to separate the properties for example will get the value 222-222-2222 . Continues From the Library of 840 Chapter 18 An Introduction to Ajax with JSON EXPLANATION continued 3 The address property also has nested property value pairs. To get the value of the state you would say . 4 JSON structure must be syntactically correct or the JavaScript eval will not be able to evaluate properly all strings quoted curly braces lined up. It appears that if you want to create an array of hashes the syntax requires an object notation rather than array notation that is use curly braces on the outside of the whole structure not . Ajax Program with JSON and eval EXAMPLE html head title Reading from an JSON file title script type text javascript function makeRequest var httpRequest if Mozilla Safari . httpRequest new XMLHttpRequest if text

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.