Ajax没有得到结果
问题描述:
我刚刚进入ajax,我不明白代码有什么问题?Ajax没有得到结果
的index.html
<html>
<head>
<title>Ajax call</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.js"></script>
<head>
<body>
<script>
var UserID = 'myname';
var EmailAddress = '[email protected]';
$.ajax({
url: "ajax.php",
type: "get", //send it through get method
data:
{
ajaxid: 4,
UserID: UserID,
EmailAddress: EmailAddress
},
success: function(response)
{
//Do Something
Alert("Sucess");
},
error: function(xhr)
{
//Do Something to handle error
Alert("Failure");
}
});
</script>
</body>
</html>
ajax.php
<?php
foreach ($_GET as $key => $value) {
echo $key . ' => ' . $value . '<br />';
}
?>
解决这个问题后,我的主要目标是与连接功能,以取代在php文件中的代码到SQL Server并使用ajax调用发送的数据检索一些数据。 我会稍后再试。
问候, 埃利奥·费尔南德斯
答
变化Alert("smth")
到alert("smth")
然后在success
功能,你需要 “发送” 服务器响应的HTML
success:function(response){
alert('success')
$('body').append(response)
}
巴特,成功消息现在显示。为什么在php文件中没有GET全局arry的回显? –
我刚编辑我的答案。立即尝试 – Bart
谢谢,它的工作。 :-) –