Created
June 16, 2020 13:58
-
-
Save mansarip/7655cd62fd7d08bfa3bfb91f11a48cb0 to your computer and use it in GitHub Desktop.
Dapatkan Token Dari LocalStorage Dan Pass Ke PHP
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
<?php | |
if (isset($_POST['token'])) { | |
echo $_POST['token']; | |
exit; | |
} | |
?> | |
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<title>Sample</title> | |
<script src="https://unpkg.com/[email protected]/dist/jquery.slim.min.js"></script> | |
</head> | |
<body> | |
<form method="post" action=""> | |
<input type="hidden" id="token-field" value="" name="token" /> | |
<button type="submit">Submit</button> | |
</form> | |
<script> | |
/** | |
* bila document ready je, | |
* terus amik value dari localStorage | |
* dan setkan ke dalam value input hidden. | |
* bila form submit, dia akan bawak sekali | |
*/ | |
$(document).ready(function() { | |
var token = localStorage.getItem('token'); | |
$('#token-field').val(token); | |
}); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment