Created
January 10, 2014 14:42
-
-
Save anytizer/8355393 to your computer and use it in GitHub Desktop.
jquery post handling
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
<?php | |
if($_POST) | |
{ | |
$data = array( | |
'time' => time().'-'.mt_rand(1000, 9999), | |
'username' => $_POST['username'], | |
'password' => $_POST['password'], | |
); | |
echo '<pre>', print_r($data, true), '</pre>'; | |
die(); | |
} | |
?> | |
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | |
<html xmlns="http://www.w3.org/1999/xhtml"> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | |
<title>jQuery POST</title> | |
<style type="text/css"> | |
#again { cursor:pointer; } | |
</style> | |
</head> | |
<body> | |
<div id="response"></div> | |
<div id="again">Test Again</div> | |
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script type="text/javascript"> | |
function attempt() | |
{ | |
$.post( | |
'?self=true', | |
{ | |
username: 'User Name', | |
password: 'Password' | |
}, | |
function(data) | |
{ | |
$('#response').html(data); | |
} | |
); | |
} | |
$('#again').click(attempt); | |
attempt(); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment