Last active
December 14, 2015 19:08
-
-
Save killercup/5134073 to your computer and use it in GitHub Desktop.
Form Test: Create JS Form to POST cross-domain. You can take a local form, do stuff with it an then POST it to another domain using a newly created form element. This will of course not work with AJAX but change the actual window.location.
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
<!doctype html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>Form Test</title> | |
<script src="http://code.jquery.com/jquery-1.8.1.min.js"></script> | |
<script> | |
jQuery(function($) { | |
$('form.original').live('submit', function(ev) { | |
ev.preventDefault(); | |
var $f = $(this); | |
console.log("Form submit triggered."); | |
setTimeout(function() { | |
var new_form = $('<form method="POST" action="http://sweet-sweet-testing.dev/"></form>'); | |
new_form.hide(); | |
new_form.append('<input name="name" value="'+$f.find('input[name=name]').val()+'"/>'); | |
console.log("Submitting new form.", new_form); | |
$('body').append(new_form); | |
new_form.submit(); | |
}, 5000); | |
return false; | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<form class="original" action="." method="POST"> | |
<input type="text" name="name" placeholder="Name?" /> | |
<input type="submit" value="Senden"> | |
</form> | |
</body> | |
</html> |
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
sys = require 'util' | |
express = require 'express' | |
app = express() | |
app.use express.bodyParser() | |
welcome = "Sup? Imma gonna collect POST data" | |
template = (json) -> | |
"""<!doctype html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>POST Parameters</title> | |
</head> | |
<body> | |
<pre> | |
#{json} | |
</pre> | |
</body> | |
</html>""" | |
app.get "/", (req, res) -> | |
res.send 200, welcome | |
app.post "/", (req, res) -> | |
sys.puts "Got one! #{if req.body?["name"]? then req.body["name"]}" | |
res.send 200, template(JSON.stringify(req.body, null, 2)) | |
sys.puts welcome | |
app.listen 8666 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment