duanhe6464 2019-04-12 04:15
浏览 33

方法声明不在生产服务器上工作,在localhost上工作

When AJAX is calling my laravel method, the method is called, but the var for the search term is null (Using Select2 for my combobox). However, the same code runs fine on my local dev machine.

I've updated laravel to 5.8.11 to see if that would help as my local machine was running a slightly newer build, php, reviewed logs, chrome inspector, nothing shows any errors for this.

   public function get_codes(Request $request)
    {
        $search = trim($request->q);

        if(empty($search))
        {
            return response()->json([]);
        }     

        $data = [];
        $data = DB::table("codes")
                ->select("id","dx_code", "description")
                ->where('dx_code','LIKE',"$search%")
                ->get();

        return response()->json($data);
    }
    ajax: {
            url: "/dxcodes",
            dataType: "json",
            delay: 250,
            data: function (params) {
              return {
                q: $.trim(params.term)
              };
            },
            processResults: function (data) {
              return {
                results: data
              };
            },
            cache: true
        }

my json response is: [] (after running tests, I found my $request->q is treated as empty) however, if I remove the if(empty), I get my response. I don't understand it... again, please remember, all this works perfectly on my local machine. I have other ajax calls in my app on the production server and they work fine, it's just this one call.

The fix for this issue was the nginx web server config file for this site was not set correctly. Nginx doesn't use .htaccess files. The ? was missing after index.php

   try_files $uri $uri/ /index.php$query_string; (BAD)
   try_files $uri $uri/ /index.php?$query_string; (GOOD)
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
    • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
    • ¥15 MATLAB中streamslice问题
    • ¥15 如何在炒股软件中,爬到我想看的日k线
    • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
    • ¥15 seatunnel 怎么配置Elasticsearch
    • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
    • ¥15 (标签-MATLAB|关键词-多址)
    • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
    • ¥500 52810做蓝牙接受端