Php jquery获取JSON问题
我是服务器验证新手,我在网络上找遍了,什么都找不到。我试图用php验证表单,方法是将表单发布到自身,并根据表单是否有效在数组中返回1或0。这很好,但我遇到的问题是,如果结果为1,我希望使登录屏幕淡出。我不能让它工作 这是我的密码: PHPPhp jquery获取JSON问题,php,jquery,json,forms,validation,Php,Jquery,Json,Forms,Validation,我是服务器验证新手,我在网络上找遍了,什么都找不到。我试图用php验证表单,方法是将表单发布到自身,并根据表单是否有效在数组中返回1或0。这很好,但我遇到的问题是,如果结果为1,我希望使登录屏幕淡出。我不能让它工作 这是我的密码: PHP if ($valid == 1) { $isvalid = array('valid' => $valid); echo json_encode(array_values($isvalid)); }; javascript <script
if ($valid == 1) {
$isvalid = array('valid' => $valid);
echo json_encode(array_values($isvalid));
};
javascript
<script>
$(document).ready(function(){
$('#login_button').click(function(){
$.getJSON("/index.php",function(result){
console.log(result);
});
});
});
</script>
(我拍摄了一个屏幕截图,因为它在控制台中停留的时间不足以让我阅读)您的响应数据与回调函数中的
result
变量相同,因此更改:
console.log(json);
到
您正在调用
console.log(json)
,但是回调的参数是result
。很抱歉,我想编辑这篇文章,但它不允许我这样做$(document).ready(function(){$('#login_按钮')。单击(function(){$.getJSON(“/index.php”,function(result){console.log(result);});});仍然没有返回结果“网络”选项卡是否显示了有用的内容?或者,如果chrome不可用,这个程序更适合同样的用途。另外,我将为您进行编辑。您的index.php文件是否位于文档根目录下?如果没有,请尝试将“/index.php”更改为“index.php”。是的,它位于根目录上。我正在运行XAMP来测试这一点,因此包含JavaScript、php和html的站点都位于localhost/index.php上
<script>
$(document).ready(function(){
$('#login_button').click(function(){
$.getJSON("index.php",$('#Login').serialize(),function(result){
alert(result);
})
.error(function(error) { alert(error); console.log(error); })
})
});
</script>
object ready state: 0
getResponseHeader: Function
getAllRequestHeaders: Function
SetRequestHeader: Function
overrideimetype: function
console.log(json);
console.log(result);