Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Quick MongoHQ ajax demo
<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