- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
Ajax 无法正常工作。有人可以帮我吗?
在 Blade 中
<div class="col-xl-8 col-lg-8 col-12 form-group" id="div-type">
<label>Expense Type</label>
<select class="select2" name="type" id="selectType">
<option></option>
<option value="Teacher's Salary" {{ old('type')=="Teacher's Salary" ? 'selected' : '' }}>
Teacher's Salary
</option>
<option value="Staff's Salary" {{ old('type')=="Staff's Salary" ? 'selected' : '' }}>Staff's
Salary
</option>
</select>
</div>
<div id="div-name" class="hidden"></div>
jquery Ajax 代码
$('#selectType').on('change', function () {
if ($(this).val() == "Teacher's Salary") {
$('#content').hide();
$.ajax({
url: "{{ route('fetch-data') }}",
method: 'GET',
data: {type: 'teacher'},
dataType: 'json',
success: function (data) {
alert(data);
$('#div-type').attr('class', 'col-xl-4 col-lg-4 col-12 form-group');
$('#div-name').attr('class', 'col-xl-4 col-lg-4 col-12 form-group');
$('#div-name').html(data);
$('#teacher_name').select2();
},
});
} else if ($(this).val() == "Staff's Salary") {
$('#content').hide();
} else {
$('#content').show();
}
});
在 web.php
Route::get('/fetch', 'ExpenseController@ajaxFetch')->name('fetch-data')
在 Controller 中
public function ajaxFetch(Request $request)
{
if ($request->ajax()) {
$type = $request->get('type');
if ($type == 'teacher') {
$names = Teacher::all();
$data = '
<label>Select Teacher</label>
<select id="teacher_name" class="select2">
';
foreach ($names as $item) {
$data+='<option value="'+$item->id+'">'+$item->name+'</option>';
}
$data+='</select>';
}
return json_encode($data);
}
}
现在它不起作用了。在控制台中 GET http://localhost/scl-mgt-update/fetch?type=teacher 500(内部服务器错误)来自 AJAX laravel 此错误显示。我现在可以做什么来运行ajax?相同的代码正在用于搜索。当我在 Controller 中生成数据时,它会向我发送错误。否则 ajax 警报会起作用。
最佳答案
这样做,+
在jquery中使用。
在php中使用
public function ajaxFetch(Request $request)
{
if ($request->ajax()) {
$type = $request->get('type');
if ($type == 'teacher') {
$names = Teacher::all();
$data = '
<label>Select Teacher</label>
<select id="teacher_name" class="select2">
';
foreach ($names as $item) {
$data .= '<option value="'.$item->id.'">'.$item->name.'</option>';
}
$data .='</select>';
}
return json_encode($data);
}
}
关于javascript - 从 AJAX laravel 获取 http ://localhost/scl-mgt-update/fetch? type=teacher 500(内部服务器错误),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61898953/
我为 HTTP 流量启动并运行了 Mgt 开发环境 docker 镜像,并想测试 https/ssl 流量 - 这就是我所做的: 在此处创建了新的自签名证书:http://www.selfsigned
我想通过 Xilinx FPGA 的 MGT channel 发送信号(不管是什么类型的信号,只是随机二进制)。这是用于测试 PCB 上的 MGT 走线。我可以实现这一目标的最简单方法是什么?对于常规
我可以将我的存储过程的“核心”作为一个巨大的查询来运行。在 SQL Management Studio 中就可以了。此外,我什至可以在 SQL Management Studio 中右键单击并“执行”
我们使用 Apache Shiro 一段时间了,没有出现任何问题,但最近注意到用户在尝试登录或注销我们的应用程序后收到以下错误: java.lang.IllegalArgumentException:
我希望我的查询结果(返回一行)显示在这样的文本中: columnA: value columnB: value columnC: value 就像在mysql中使用时发生的那样 select * fr
当我在 SQL Server Mgt Studio 中执行查询时,我有一个快速运行的查询(不到 1 秒),但是当我在 PHP 中运行完全相同的查询时(在同一个数据库实例上)使用 FreeTDS v8,
最近在使用 Cocoa 后转向 iOS,我很吃惊地收到一个带有以下错误的 SIGABRT:“-[UIDeviceRGBColor copyWithZone:]: unrecognized select
我在 Windows 8.1 上使用 Mgt 开发环境 (mgtcommerce/mgt-development-environment-5.6)。 & 适用于 Windows 的 DockerToo
Ajax 无法正常工作。有人可以帮我吗? 在 Blade 中 Expense Type Teacher's Salary
我是一名优秀的程序员,十分优秀!