Javascript 阿贾克斯赢了';不适用于url l中包含id的页面?

Javascript 阿贾克斯赢了';不适用于url l中包含id的页面?,javascript,php,ajax,laravel-5,Javascript,Php,Ajax,Laravel 5,我不熟悉使用ajax。我有一个ajax程序,当一个人在搜索栏中查找用户时,它会对用户进行实时搜索。它所做的是在每个键上使用ajax从数据库中获取数据进行推荐,以帮助用户进行选择。 但问题是,除了编辑和显示特定数据的页面外,它对大多数页面都有效 这里是ajax function suser(str){ var xhttp; if(str.length==0) { document.getElementById("srtd").innerHTM

我不熟悉使用ajax。我有一个ajax程序,当一个人在搜索栏中查找用户时,它会对用户进行实时搜索。它所做的是在每个键上使用ajax从数据库中获取数据进行推荐,以帮助用户进行选择。 但问题是,除了编辑和显示特定数据的页面外,它对大多数页面都有效

这里是ajax

   function suser(str){

        var xhttp;
        if(str.length==0)
        { document.getElementById("srtd").innerHTML = "" 
            document.getElementById("srtd").style.border="0px";
            return;}
        else{
        if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
        } else {
        // code for IE6, IE5
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            xhttp.onreadystatechange = function() {
        if (xhttp.readyState == 4 && xhttp.status == 200) {
            var res=xhttp.responseText;
            var i=JSON.parse(res);
            var j=i.length;
            document.getElementById("srtd").innerHTML = "";
          var  d=document.getElementById("srtd");
        var u=document.createElement("ul");
        u.style="list-style-type:none";

            d.appendChild(u);
            for(var k=0; k<j ; k++){
         var    li=document.createElement("li");

         u.appendChild(li);
            li.innerHTML="<a href='livsearres/"+ i[k].id +"' class='btn' >"+ i[k].name +" "+i[k].fname+" "+i[k].gname+"</a>";

            }
            //document.getElementById("srtd").innerHTML="<a href='showuser/"+ i[0].id +"' class='btn mybtn-n' >"+ i[0].name +" "+i[0].fname+"</a>";


        }
      }
      xhttp.open("GET", "lusrser/"+str, true);
      xhttp.send();}
    }
在每个页面上都有相似的搜索输入

<input   onkeyup="suser(this.value)" type="search" name="search" class="form-control"  placeholder="Search" >
因为只有showuser和edituser不起作用,我认为这与正在编辑或显示的id的附加数据有关。任何人都可以帮助我解决这个问题

错误消息是

Sorry, the page you are looking for could not be found.

1/1
NotFoundHttpException in RouteCollection.php line 161:
in RouteCollection.php line 161
at RouteCollection->match(object(Request)) in Router.php line 821
at Router->findRoute(object(Request)) in Router.php line 691
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54

如果您使用的是刀片文件,则可以使用此技巧

像这样定义一个JavaScript变量

var SiteUrl = '{{ url::to("") }}';
xhttp.open("GET", SiteUrl+"lusrser/"+str, true);
你可以像这样用你的ajaxurl来处理这个问题

var SiteUrl = '{{ url::to("") }}';
xhttp.open("GET", SiteUrl+"lusrser/"+str, true);

如果您在baseURL的末尾添加了
'/'
,那么请使用上面的命令,否则您可以使用
xhttp.open(“GET”,SiteUrl+“/lusrser/”+str,true)

您在xhr(控制台)中遇到了什么错误?我猜问题出在
xhtp.open(“GET”,“lusser/”+str,true)。它没有点击你想要的URL,因为你的URL中有参数。我认为你是正确的,因为它显示了route not found,这意味着URL不正确。我该怎么解决这个问题呢?检查我的答案,伙计。我想这会帮助你理解这个问题。