[英]Jquery Ajax POST method is not working, return undefined value
POST method return undefined value , but GET method working fine. POST 方法返回undefined 值,但 GET 方法工作正常。 I even tried
$.post(url, data, success);
我什至试过
$.post(url, data, success);
<< $.post
even worse GET and POST can't work. <<
$.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 ajax.php
<?php echo $_POST['action'];?>
Use method
instead of type
:使用
method
而不是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添加了 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.