Skip to content

Commit f2d2d7c

Browse files
author
Jesse House
committed
new recipe: jquery ajax
1 parent 2464b33 commit f2d2d7c

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

chapters/jquery/ajax.textile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
---
2+
layout: recipe
3+
title: Ajax
4+
chapter: jQuery
5+
---
6+
7+
h2. Problem
8+
9+
You need to make an ajax request using jQuery.
10+
11+
12+
h2. Solution
13+
14+
{% highlight coffeescript %}
15+
jQuery ->
16+
console.log "document loaded"
17+
$('form').submit (e) ->
18+
console.log "form submit"
19+
e.preventDefault()
20+
form = this
21+
22+
$.ajax
23+
type: "POST"
24+
url: $(form).attr('action')
25+
data: $(form).serialize()
26+
success: ->
27+
console.log("success")
28+
{% endhighlight %}
29+
30+
31+
h2. Discussion
32+
33+
The jQuery and $ variables can be used interchangeably. See also "Callback bindings":../jquery/callback-bindings-jquery.

wanted-recipes.textile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ console.log [1,2,3,4,5].map (x) ->
108108

109109
h2. jQuery
110110

111-
* jQuery AJAX from CS
111+
*
112112

113113
h2. Regular Expressions
114114

0 commit comments

Comments
 (0)