javascript - Ajax 数据未显示在控制台日志中,但给出错误“http://localhost/IFICSV3/public/sla/sla/getbranch/180 not found”
问题描述
我尝试使用 ajax 使下拉选项依赖。我想在控制台中查看数据是否成功。我希望数据显示在控制台日志中,但给出错误
这是我查看 ajax 的代码
if(country_id) {
//console.log(country_id);
$.ajax ({
url: 'sla/getbranch/'+country_id,
//url: "{{ route('sla.getbranch') }}"+country_id,
type: 'GET',
datatype: 'json',
success: function(data){
console.log(data);
}
})
我的控制器
public function index()
{
$custList = $this->hdcustomermaster->getAllCustomerActiveSts();
return view('sla.slm.SLAList', compact('custList'));
}
public function getbranch($id)
{
$data=HDCustomerBranch::where('cb_customer_ID',$id)->pluck('cu_customer_ID','cu_customer_Name');
return json_encode($data);
}
我的 web.php
Route::group(['prefix' => 'sla'], function () {
Route::get('/','SlaController@index');
Route::resource('sla', 'SlaController');
Route::get('sla/getbranch','SlaController@getbranch')->name('sla.getbranch');
});
解决方案
像这样替换您的路线
Route::group(['prefix' => 'sla'], function () {
Route::get('/','SlaController@index');
Route::resource('sla', 'SlaController');
Route::get('sla/getbranch/{id}','SlaController@getbranch')->name('sla.getbranch');
});
这里的问题是您在该路线中将 180 作为参数传递。但是您没有在您的路线中声明该参数。您也可以添加一个“?” 如果它是一个可选参数,像这样
Route::get('sla/getbranch/{?id}','SlaController@getbranch')->name('sla.getbranch');
推荐阅读
- reactjs - 如何在本地 WiFi 上公开从 WSL 运行的服务器/网站/服务?
- plsql - 有人可以请告诉我有什么问题吗?ORACLE APEX 中的 PLSQL
- sql-server - 如何为 EF 核心迁移历史记录表设置自定义名称并在生成迁移脚本时使用它?
- python - 为什么嵌套字典不能正确附加到列表中?
- javascript - 即使循环还没有完成迭代,一行代码也会运行吗?
- google-apps-script - 异常:获取对象 ContactsApp 上的方法或属性 getContactGroups 时出现意外错误
- python - cppzmq:使用 zmq::send_multipart 时对非套接字的套接字操作
- java - 对某些逻辑正确使用多态性和继承
- excel - 对现有数据应用宏
- html - 如何将元素的高度设置为等于另一个元素?(包括 Codepen)