Php $.getJSON don';我不能在本地网站的第二个链接页面工作

Php $.getJSON don';我不能在本地网站的第二个链接页面工作,php,html,json,get,localhost,Php,Html,Json,Get,Localhost,我对$.getJSON函数有问题。get在我的第一个页面index.html上运行良好。但是,当我转到第二个页面second.html并使用函数$.getJSON时,我得到一个错误 代码(second.html)不起作用: $(document).ready(function(){ $('button').click(search); }); function search(){ var name = $('#inputName').val(); $.getJSON("a

我对
$.getJSON
函数有问题。get在我的第一个页面index.html上运行良好。但是,当我转到第二个页面second.html并使用函数
$.getJSON
时,我得到一个错误

代码(second.html)不起作用:

$(document).ready(function(){
   $('button').click(search);
});

function search(){
    var name = $('#inputName').val();
    $.getJSON("api/research_name.php?nome="+nome, function(data){
        console.log(data);
    });
}
此代码(index.html)工作正常:

$(document).ready(function(){
   $('button').click(search);
});
function search(){
    var name = $('#inputName').val();
    $.getJSON("api/research_name.php?nome="+nome, function(data){
        console.log(data);
    });
}
(作为评论,这可能会更好,但是)

检查你的代码。将
name
分配给输入字段的值,但在.getJSON调用中使用
nome

此外,您可能应该使用完全限定的URL。例如,如果您的层次结构是

/index.html

/文件夹/something/second.html

然后,您的api调用将与调用它的目录相关,该目录可能不是根目录


考虑将其更改为
“/api/research\u name.php?nome=“+nome

您得到了什么错误?