我试图根据第一个保管箱中选择的值来获取第二个保管箱上的记录。我在第一个保管箱中的值正在加载,但是当我选择一个随机值时,第二个值中没有任何值。我在浏览器中检查了控制台,并显示了错误(500个内部服务器错误)。
但是,当它在本地主机上运行时,它绝对可以正常工作。 仅当在Live Server上运行时会发生此错误
我有一个包含此表单的主侧栏文件。而ajax代码是
$(document).ready(function(){
$('.dynamic').change(function(){
if($(this).val() != '')
{
var select = $(this).attr("id");
var value = $(this).val();
var dependent = $(this).data('dependent');
var _token = $('input[name="_token"]').val();
$.ajax({
url:"{{ route('pagescontroller.fetch') }}",
method:"POST",
data:{select:select, value:value, _token:_token, dependent:dependent},
success:function(result)
{
$('#'+dependent).html(result);
}
})
}
});
)};
我在控制器中的代码:-
public function index(){
$pc = $this->getPostcodes();
$cl = $this->carFetch();
return view('home')->with('postcodes', $pc)->with('carLists', $cl);
}
public function getPostcodes(){
$postcodes = DB::table('postcodes')
->get();
return $postcodes;
}
public function carFetch(){
$carLists = DB::table('carlists')
->groupBy('Make')
->get();
return $carLists;
}
function fetch(Request $request)
{
$select = $request->get('select');
$value = $request->get('value');
$dependent = $request->get('dependent');
$data = DB::table('carLists')
->where($select, $value)
->groupBy($dependent)
->get();
$output = '<option value="">Select '.ucfirst($dependent).'</option>';
foreach($data as $row)
{
$output .= '<option value="'.$row->$dependent.'">'.$row->$dependent.'</option>';
}
echo $output;
}
我的路线:-
Route::get('/', 'PagesController@index')
Route::post('sidebar/fetch', 'PagesController@fetch')->name('pagescontroller.fetch');
不确定其如何在localhost而不是实时服务器上工作。
答案 0 :(得分:1)
请检查
Making all in man
make[5]: Entering directory '/test/ruby-2.4.5/tst/ext/fiddle/libffi-3.2.1/man'
make[5]: Nothing to be done for 'all'.
make[5]: Leaving directory '/test/ruby-2.4.5/tst/ext/fiddle/libffi-3.2.1/man'
make[5]: Entering directory '/test/ruby-2.4.5/tst/ext/fiddle/libffi-3.2.1'
CC src/prep_cif.lo
CC src/types.lo
CC src/raw_api.lo
CC src/java_raw_api.lo
CC src/closures.lo
CC src/powerpc/ffi_darwin.lo
../../../../ext/fiddle/libffi-3.2.1/src/powerpc/ffi_darwin.c: In function 'ffi_p rep_args':
../../../../ext/fiddle/libffi-3.2.1/src/powerpc/ffi_darwin.c:112:17: warning: un used variable 'abi' [-Wunused-variable]
const ffi_abi abi = ecif->cif->abi;
^
CPPAS src/powerpc/aix.lo
libtool: compile: unable to infer tagged configuration
libtool: compile: specify a tag with `--tag'
Makefile:1335: recipe for target 'src/powerpc/aix.lo' failed
make[5]: *** [src/powerpc/aix.lo] Error 1
make[5]: Leaving directory '/test/ruby-2.4.5/tst/ext/fiddle/libffi-3.2.1'
Makefile:1596: recipe for target 'all-recursive' failed
make[4]: *** [all-recursive] Error 1
make[4]: Leaving directory '/test/ruby-2.4.5/tst/ext/fiddle/libffi-3.2.1'
Makefile:730: recipe for target 'all' failed
make[3]: *** [all] Error 2
make[3]: Leaving directory '/test/ruby-2.4.5/tst/ext/fiddle/libffi-3.2.1'
Makefile:370: recipe for target 'libffi-3.2.1/.libs/libffi_convenience.a' failed
make[2]: *** [libffi-3.2.1/.libs/libffi_convenience.a] Error 2
make[2]: Leaving directory '/test/ruby-2.4.5/tst/ext/fiddle'
exts.mk:212: recipe for target 'ext/fiddle/all' failed
make[1]: *** [ext/fiddle/all] Error 2
make[1]: Leaving directory '/test/ruby-2.4.5/tst'
uncommon.mk:220: recipe for target 'build-ext' failed
make: *** [build-ext] Error 2
在carFetch中,您将表格名称用作汽车列表
但是在获取中,您使用表名作为carLists
Linux服务器区分大小写:)
DB::table('carlists')
(or)
DB::table('carLists')
到
$request->get('select');
答案 1 :(得分:1)
您需要检查.htaccess文件。任何语法错误都会导致显示500 Internal Server Error消息。要确认.htaccess配置是否错误是500 Internal Server错误的原因,请暂时删除或重命名.htaccess文件并进行检查。
答案 2 :(得分:1)
500错误表示您的控制器存在错误,请将其放入JavaScript代码:
...
success:function(result)
{
$('#'+dependent).html(result);
},
error: function(result) {
console.log(result);
}
...
因此,您可以在控制台中读取错误,并在评论中发布图像以进行纠正。