<script>
var er ="hi";
$( "#save" ).click(function() {
var er = $('#edit').val();
alert(er);
});
$.ajax({
type: 'POST',
url: 's.php',
data: { er:er},
success: function(response) {
alert(er);
}
});
</script>
You must write the ajax code in click function, otherwise ajax code will execute on page load.
var er ="hi";
$( "#save" ).click(function() {
var er = $('#edit').val();
alert(er);
$.ajax({
type: 'POST',
url: 's.php',
data: {'er':er},
success: function(response) {
alert(er);
}
});
});
Try above code. it will work for you.