Created
February 2, 2012 21:55
-
-
Save tjmehta/1726019 to your computer and use it in GitHub Desktop.
The Elevator Game Hack
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
(function clickIt() { | |
var $form = $("form"); //the only form on the page is the elevator button of interest. | |
var postURL = $form.attr("action"); //post url of the form | |
var postData = {}; | |
var inputs = $("input", $form); | |
for (var i = inputs.length; i--;) { | |
// serialize the form elements into an object | |
postData[inputs.eq(i).attr("name")] = inputs.eq(i).val(); | |
} | |
//clicking the elevator button of interest was submitting a form contained w/in it | |
//ive 'ajaxified' the form submit below | |
$.ajax({ | |
url: postURL, | |
type: 'POST', | |
data: postData, | |
success: function(responseHtml) { | |
// I tried parsing out the body via jquery but it was having some issues | |
// so ive parsed out the body manually. | |
var bodyStartIndex = responseHtml.indexOf("<body>"); | |
var bodyEndIndex = responseHtml.indexOf("</body>")+7; | |
var bodyLength = bodyEndIndex - bodyStartIndex; | |
var bodyHtml = responseHtml.substr(bodyStartIndex, bodyLength); | |
$("body").html(bodyHtml); //replace the body with the response body | |
setTimeout(clickIt,0);// recursion via callback added stability.... | |
} | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
My hold