Created
February 1, 2013 07:40
-
-
Save robertcedwards/4689953 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://code.jquery.com/jquery-latest.js"></script> | |
</head> | |
<body> | |
<form action="https://api.electricimp.com/v1/d8a33309dbb0d293/30420cd686f1a2a2" id="searchForm"> | |
<input type="hidden" id="value" name="value" value="1"> | |
<input type="submit" value="Turn Coffee Pot On"> | |
</form> | |
<form action="https://api.electricimp.com/v1/d8a33309dbb0d293/306b487a2ba03bf0" id="searchForm2"> | |
<input type="hidden" id="value" name="value" value="0"> | |
<input type="submit" value="Turn Coffee Pot Off"> | |
</form> | |
<!-- the result of the search will be rendered inside this div --> | |
<div id="result">1</div> | |
<script> | |
/* attach a submit handler to the form */ | |
$("#searchForm").submit(function(event) { | |
/* stop form from submitting normally */ | |
event.preventDefault(); | |
/* get some values from elements on the page: */ | |
var $form = $( this ), | |
term = $form.find( 'input[name="s"]' ).val(), | |
url = $form.attr( 'action' ); | |
/* Send the data using post */ | |
var posting = $.post( url, { s: term } ); | |
/* Put the results in a div */ | |
posting.done(function( data ) { | |
var content = $( data ).find( '#content' ); | |
$( "#result" ).empty().append( content ); | |
}); | |
}); | |
$("#searchForm2").submit(function(event) { | |
/* stop form from submitting normally */ | |
event.preventDefault(); | |
/* get some values from elements on the page: */ | |
var $form = $( this ), | |
term = $form.find( 'input[name="s"]' ).val(), | |
url = $form.attr( 'action' ); | |
/* Send the data using post */ | |
var posting = $.post( url, { s: term } ); | |
/* Put the results in a div */ | |
posting.done(function( data ) { | |
var content = $( data ).find( '#content' ); | |
$( "#result" ).empty().append( content ); | |
}); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment