Reputation: 328
POST method return undefined value, but GET method working fine. I even tried $.post(url, data, success);
<< $.post
even worse GET and POST can't work.
<input type="submit" value="submit" id="btnUpload">
$('#btnUpload').click(function(){
$.ajax({
type: 'POST',
url: 'ajax.php',
data: { 'action': 'scan_email' },
success: function(response) {
alert(response);
}
});
ajax.php
<?php echo $_POST['action'];?>
Upvotes: 1
Views: 1191
Reputation: 1374
Added the jquery library
<input type="button" value="submit" id="btnUpload">
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#btnUpload').on('click', function(){
$.ajax({
type: "POST",
url: "login.php",
data: { 'action':'scan_email'},
success: function(theResponse) {
// Output from ajax.php
alert(theResponse); // comment this
}
});
});
});
</script>
Upvotes: 0
Reputation: 2073
Use method
instead of type
:
Code:
<input type="submit" value="submit" id="btnUpload">
$('#btnUpload').click(function(){
$.ajax({
method: 'POST',
url: 'ajax.php',
data: { 'action': 'scan_email' },
success: function(response) {
alert(response);
}
});
Upvotes: 1