简体   繁体   中英

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

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

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM