Book Image

JavaScript JSON Cookbook

By : Ray Rischpater, Brian Ritchie, Ray Rischpater
Book Image

JavaScript JSON Cookbook

By: Ray Rischpater, Brian Ritchie, Ray Rischpater

Overview of this book

Table of Contents (17 chapters)
JavaScript JSON Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Requesting JSON content using jQuery


jQuery defines the variable $, which exposes methods for everything you want to do with the interface. (There are ways to rename that variable, say if you're working with another JavaScript environment that uses the same variable, but I don't recommend it). Among the methods $ exposes is the ajax method, which you use to make AJAX queries. Let's see how.

How to do it...

Here's a whole page that makes an AJAX request. The AJAX code is in bold:

<!doctype HTML>
<html>
<head>
<script  type="text/javascript"
  src="//code.jquery.com/jquery-1.11.2.min.js"></script>
</head>
<body>

<p>Hello world</p>
<p>
  <div id="debug"></div>
</p>
<p>
  <div id="json"></div>
</p>
<p>
  <div id="result"></div>
</p>

<p>Powered by <a href="http://www.aprs.fi">aprs.fi</a></p>

<script>
$(function () {
  $('#debug').html("loaded...