Created
May 14, 2012 03:00
-
-
Save johnnysparks/2691538 to your computer and use it in GitHub Desktop.
Quick MongoHQ ajax demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
$(function(){ | |
// post demo | |
$.ajax({ | |
dataType: "json", | |
type: "post", | |
data: {"document" : { "name" : "Elton John", "pets": "Lorenzo" }}, | |
url: "https://api.mongohq.com/databases/gymput/collections/prospects/documents?_apikey=dmfbybnos7h10x2rrrrx", | |
success: function(response){ | |
$('#b').html(JSON.stringify(response)); | |
}, | |
complete: function(response){ | |
//$('#b').html('complete'); | |
}, | |
error: function(response){ | |
console.log( this ); | |
$('#b').html(); | |
} | |
}); | |
// get demo | |
$.ajax({ | |
dataType: "json", | |
type: "get", | |
data: {"document" : {'$set': {'name': 'mike'}}}, | |
url: "https://api.mongohq.com/databases/gymput/collections/prospects/documents/4fb066bc7734100005000001?_apikey=dmfbybnos7h10x2rrrrx", | |
success: function(response){ | |
$('#a').html(JSON.stringify(response)); | |
}, | |
complete: function(response){ | |
//$('#a').html('complete'); | |
}, | |
error: function(response){ | |
console.log( this ); | |
$('#a').html(); | |
} | |
}); | |
// get list demo | |
$.ajax({ | |
dataType: "json", | |
type: "get", | |
data: {}, | |
url: "https://api.mongohq.com/databases/gymput/collections/prospects/documents?_apikey=dmfbybnos7h10x2rrrrx", | |
success: function(response){ | |
$('#c').html(JSON.stringify(response)); | |
}, | |
error: function(response){ | |
console.log( this ); | |
$('#c').html(); | |
} | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<h1>read</h1> | |
<div id="a"> waiting </div> | |
<h1>insert</h1> | |
<div id="b"> waiting </div> | |
<h1>read many</h1> | |
<div id="c"> waiting </div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment