[英]Sending POST data with ajax from jquery to php - no response
I want to see an ajax response when submitting form in a result div ('ajax') - but cant manage to do that. 我想在结果div('ajax')中提交表单时看到ajax响应-但无法做到这一点。
What is the problem? 问题是什么? How can I achieve this? 我该如何实现? I see the post is being send in a net tab in console, but it doesnt work.... 我看到该帖子正在控制台的网络选项卡中发送,但是它不起作用。
Here is my code: 这是我的代码:
index.php file: index.php文件:
$res = isset($_POST['login']) ? $_POST['login'] : '';
print '<form id="forma">
<input type="text" name="login"/>
<input id="submit" type="submit" onclick="Javascript: AjaxForm.showForm(); return false;"/>
</form>
<div id="ajax">'.$res.'</div>'
and javascript file: 和javascript文件:
var AjaxForm =
{
showForm: function()
{
var x = $('#forma').serialize();
$.ajax({url: 'index.php', type: 'POST', data: x});
}
}
add the success property to your ajax call 将成功属性添加到您的ajax调用中
$.ajax({url: 'index.php',
type: 'POST',
data: x,
success: function(data){
//data is your response
console.log(data);
}
});
Hope this will help you 希望这个能对您有所帮助
$(document).on('submit','#forma',function(){
var data=$(this).serialize();
$.ajax({
url: "index.php",
type: "POST",
data: data,
success: function(data)
{
alert(data);
}
});
return false;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.