Skip to content

Commit 1ee6471

Browse files
committed
Add "AJAX" recipe to the jQuery chapter.
1 parent b5637a1 commit 1ee6471

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

chapters/jquery/ajax.textile

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
layout: recipe
3+
title: AJAX
4+
chapter: jQuery
5+
---
6+
7+
h2. Problem
8+
9+
You want to make AJAX calls using jQuery.
10+
11+
h2. Solution
12+
13+
{% highlight coffeescript %}
14+
$ ?= require 'jquery' # For Node.js compatibility
15+
16+
$(document).ready ->
17+
# Basic Examples
18+
$.get '/', (data) ->
19+
$('body').append "Successfully got the page."
20+
21+
$.post '/',
22+
userName: 'John Doe'
23+
favoriteFlavor: 'Mint'
24+
(data) -> $('body').append "Successfully posted to the page."
25+
26+
# Advanced Settings
27+
$.ajax '/',
28+
type: 'GET'
29+
dataType: 'html' error: (jqXHR, textStatus, errorThrown) ->
30+
$('body').append "AJAX Error: #{textStatus}"
31+
success: (data, textStatus, jqXHR) ->
32+
$('body').append "Successful AJAX call: #{data}"
33+
34+
# For jQuery 1.5+
35+
request = $.get '/'
36+
request.success (data) -> $('body').append "Successfully got the page again."
37+
request.error (jqXHR, textStatus, errorThrown) -> $('body').append "AJAX Error: ${textStatus}."
38+
39+
{% endhighlight %}
40+
41+
h2. Discussion
42+
43+
See the "jQuery AJAX API":http://api.jquery.com/jQuery.ajax/ for additional methods and options.

wanted-recipes.textile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@ console.log [1,2,3,4,5].map (x) ->
107107

108108
h2. jQuery
109109

110-
* jQuery AJAX from CS
111-
112110
h2. Regular Expressions
113111

114112
* Searching for substrings # "foo bar baz".match(/ba./) # => [ 'bar', index: 4, input: 'foo bar baz' ]

0 commit comments

Comments
 (0)