Skip to content

Commit 1e7e53f

Browse files
committed
jquery deferred continued
1 parent e13143f commit 1e7e53f

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

jquery_deferred/ajax.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
if((isset($_SERVER['HTTP_X_REQUESTED_WITH']) && $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest')) {
4+
//var_dump($_POST);
5+
print json_encode(array("firstName"=>'its-true'));
6+
7+
}
8+
9+
10+
?>

jquery_deferred/deferred.html

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!--
2+
To change this template, choose Tools | Templates
3+
and open the template in the editor.
4+
-->
5+
<!DOCTYPE html>
6+
<html>
7+
<head>
8+
<title></title>
9+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
10+
<script type="text/javascript" src="../resources/js/jquery-1.6.4.js"></script>
11+
<script language="javascript">
12+
$(function(){
13+
/*
14+
var deferred = $.Deferred();
15+
deferred.resolve("hello world");
16+
deferred.done(function(value) {
17+
alert(value);
18+
});
19+
*/
20+
var ajax_url = 'ajax.php';
21+
/*
22+
var post = $.ajax({
23+
url: ajax_url,
24+
data: {json: JSON.stringify({firstName: "Jose", lastName: "Romaniello"})} ,
25+
type: "POST"
26+
});
27+
28+
post.done(function(p){
29+
alert(p.firstName + " saved.");
30+
});
31+
32+
post.fail(function(){
33+
alert("error!");
34+
});
35+
*/
36+
37+
var post = $.post(ajax_url,
38+
{
39+
json: JSON.stringify({firstName: "Jose", lastName: "Romaniello"})
40+
}
41+
).pipe(function(p){
42+
return "Saved " + p.firstName;
43+
});
44+
45+
post.done(function(r){ alert(r); });
46+
47+
});
48+
</script>
49+
</head>
50+
<body>
51+
<div>jQuery Resolved</div>
52+
</body>
53+
</html>

0 commit comments

Comments
 (0)