Skip to content

Instantly share code, notes, and snippets.

Created October 13, 2015 21:32
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
<!doctype html>
<button onclick="addGeneratedForms()">addGeneratedForms</button>
function addGeneratedForms(){
var div = document.createElement('div');
div.innerHTML = '<form class="login" method="post" action="login">\
<input type="text" name="username">\
<input type="password" name="password">\
<button type="submit">login</button> stay on this page but update the url with pushState\
document.body.addEventListener('submit', function ajax(e){
// Works in chrome when the original login form does not "exist" anymore after push or ajax request
// So either remove (or hide) the form or try to change it's action url (didn't test but should work too)
// Also make sure all other forms within the same page point to a different action url
// otherwise they are considered as login form too.; // Or alternatively just hide the form: = 'none';
history.replaceState({success:true}, 'title', "/success.html");
// This is working too!!! (uncomment the history.xxxState(..) line above) (it works when the http response is a redirect or a 200 status)
//var request = new XMLHttpRequest();
//'POST', '/success.html', true); // use a real url you have instead of '/success.html'
//request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
}, 1);
}, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment