[英]Not getting into the function of $.getJSON
您好,我是一位新编码员,并且具有JSON的初步使用经验。 我正在从php文件中的数据库获取值,并希望使用JSON对象在javascript文件中发送它们。 但是我面临的问题是我没有进入$ .getJSON函数。 这是javascript文件中的json代码:
$(document).ready(function(){
$.getJSON("php/personal_profile/get_DoctorInfo.php", function (data) {
alert("Hello"); //NOT showing any output on the webpage.
if (data.login_status)
{
$('.doctor_profile').show();
$('#name').value(data.Name);
$('#speciality').value(data.speciality);
$('#p_checked').value(data.p_checked);
$('#p_pending').value(data.p_pending);
}
else
{
alert("You are not Logged In!");
}
});
});
在PHP文件中,我只是从数据库中获取值,然后尝试使用json_encode()函数在javascript文件中发送它们。
echo json_encode(array('login_status' => true , 'Name' => $name , 'speciality' => $speciality , 'department' => $department , 'p_checked' => $patients_checked , 'p_pending' => $patients_pending));
请帮助我.. M卡在这里..如果我使用$.get("path",function(object){alert("hello")});
它有效,但是当我使用$.get("path",function(object){alert("hello")}, "json");
那就行不通了
呼叫必须无法获取数据。 jQuery getJSON API只接受成功回调。
如果调用引发异常,则可以尝试通过失败回调进行查找。
jQuery getJSON是一个承诺,您应该能够查看是否触发了失败回调。
jQuery文档中的getJSON
$.getJSON("example.json", function() {
console.log("success");
})
.done(function() {
console.log("second success");
})
.fail(function(e) {
console.log("error");
})
.always(function() {
console.log("complete");
});
在jQuery中,getJSON ajax函数用于跨源ajax调用,因此,getJSON本身会向您发送一个附加的get变量,我猜在您的情况下是“ _”,因为您没有指定任何回调,因此在服务器端您应该对其进行响应看起来像
$_RESULT['the query string variable which you can see on console'].'('.json_encode(your array goes here).')';
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.