Txuver Jhi Wei Txuver Jhi Wei - 7 months ago 29
PHP Question

Jquery Ajax POST method is not working, return undefined value

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'];?>

Answer

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);
    }
});