[英]Not able to access the $.getJSON function
这是尝试访问$ .getJSON的代码,但没有响应。 这可能是什么原因。
function getTerms()
{
alert("hello"); //it alerts hello
$.getJSON('http://localhost/context-search.php?callback=?', function(r) {
//not here
alert("Hello");
});
}
$(document).ready(function(){
alert("hello");
getTerms();
});
context-search.php以以下形式返回json数据:
{“选项”:[“ osi”,“ tcp”,“ ip”,“ http协议”,“以太网”,“网络协议”,“协议含义\\ n”]}
我可能在哪里出错了? 请帮我解决这个问题! 谢谢!! :)
您检查控制台日志了吗? 如果不包含错误,请改为执行json请求
$.ajax({
url: url,
dataType: 'json',
data: data,
success: function(){},
error: function(jqXHR, textStatus, errorThrown) {
console.log("error " + textStatus);
console.log("incoming Text " + jqXHR.responseText);
}
});
这将为您提供适当的错误处理。
可能是相同的原产地政策 。 假设这在本地主机上运行,您是否尝试过
$ .getJSON('/ context-search.php?callback =?',...);
这样使用
$(document).ready(function(){
$.getJSON('/ITTA/SavePreference/?t=' + new Date(), { id: id3 },
function (data) {
if (data != null && data != undefined && data != '') {
top.location.href = '/ITTA/Entries/' + id3;
}
}); });
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.