【发布时间】:2019-11-16 10:42:30
【问题描述】:
我正在编写一个 Laravel 应用程序并尝试实现一个显示元素细节的模式。当我单击链接时,背景会显示,但不会显示模态窗口。在 chrome 的网络监视器中,它正在预览中显示模态窗口。
怎么了?
提前感谢您的帮助!
这是我的代码
index.blade.php
<td>
<a href="{{ route('projects.show', $project->id) }}" class="btn btn-info" data-remote="true">Details</a>
</td>
modal.blade.php
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">@yield('title')</h5>
</div>
<div class="modal-body">
@yield('content')
</div>
<div class="modal-footer">
@yield('footer')
</div>
</div>
</div>
show.blade.php
@extends('layouts.modal')
@section('title')
Demo Modal
@endsection
@section('content')
<p>test</p>
@endsection
@section('footer')
<button type="button" data-dismiss="modal">Close</button>
@endsection
remote.js
$(document).on('ajax:success', function(e, xhr){
if(!$('#modal').length){
$('body').append($('<div class="modal" id="modal"></div>'))
}
$('#modal').html(xhr.responseText).modal('show');
});
ProjectController.php
public function show($id)
{
$project = Project::findOrFail($id);
return view('projects.show', compact('project'));
}
【问题讨论】:
-
您是否尝试在 ajax 成功后调用模态?你看到你的元素 html 使用检查元素了吗?
-
您是否在浏览器
console中遇到任何错误? -
@DhananjayKyada 不,我没有收到任何错误?
-
@Jovs 在 js 文件中你会看到我正在用它做的所有事情。使用检查器时看不到 html 元素
-
那说明你的ajax不成功
标签: php jquery laravel twitter-bootstrap