POST方法返回未定义值,但GET方法正常工作。我甚至试过$.post(url, data, success);
<< $.post
更糟糕的是GET和POST无法正常工作。
<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'];?>
答案 0 :(得分:1)
使用method
代替type
:
<强>代码:强>
<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);
}
});
答案 1 :(得分:0)
添加了jquery库
<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>