Skip to content

Instantly share code, notes, and snippets.

@larek
Last active March 24, 2017 16:40
  • Star 0 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
Save larek/b5a859febccdf8d643429eeb24d8f20f to your computer and use it in GitHub Desktop.
Simple jquery post request
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title></title>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js'></script>
<script>
$(document).ready(function(){
// Click on the button
$(".btn-send").click(function(){
// Get values
var data1 = $(".data1").val();
var data2 = $(".data2").val();
// Send POST request
$.post('/server.php',{data1: data1, data2:data2 }).done(function(response){
$(".result").html(response)
});
});
});
</script>
</head>
<body>
<button class="btn-send">Кнопка</button>
<input type="text" class='data1'>
<input type="text" class='data2'>
<div class="result"></div>
</body>
</html>
<?= $_POST['data1'] + $_POST['data2'];?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment