Javascript 如何从blade文件中获取内容并在laravel中动态显示在modals中

Javascript 如何从blade文件中获取内容并在laravel中动态显示在modals中,javascript,php,jquery,ajax,laravel,Javascript,Php,Jquery,Ajax,Laravel,我有五种不同的模态形式和它们的js,当它们对应的按钮被点击时会显示出来,把所有模态和其他内容放在一个blade文件中会很混乱 我想在页面上只有一个空白模式,该模式将由与其按钮点击相关的内容填充。有没有什么方法可以把我的五种不同的情态内容放到五个不同的刀片文件中,当主页上的按钮被点击时,我从相关的模态刀片文件中获取内容,并将其填入空白模式,并加载它的JS? < P>是的,你可以。 在控制器中,假设您有一个名为create的方法,并且希望将其响应放入模态体中 <?php namespace A

我有五种不同的模态形式和它们的js,当它们对应的按钮被点击时会显示出来,把所有模态和其他内容放在一个blade文件中会很混乱

我想在页面上只有一个空白模式,该模式将由与其按钮点击相关的内容填充。有没有什么方法可以把我的五种不同的情态内容放到五个不同的刀片文件中,当主页上的按钮被点击时,我从相关的模态刀片文件中获取内容,并将其填入空白模式,并加载它的JS?

< P>是的,你可以。

在控制器中,假设您有一个名为create的方法,并且希望将其响应放入模态体中

<?php
namespace App\Http\Controllers;
class SomeController extends Controller{

  public funtion create(){
    $someVariable;
    $view=\View::make::('directory.your_blade_file',compact('someVariable'));
    return ['html'=>$view->render()];
  }
}

你能举个例子吗?我搞不懂你想干什么?
<div class="modal" id="single-modal-in-the-page" tabindex="-1" role="dialog">
 <div class="modal-dialog" role="document">
   <div class="modal-content">
    <div class="modal-header">
    <h5 class="modal-title">Modal title</h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">

  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-primary">Save changes</button>
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  </div>
</div>
<script>
 $(function(){
   $('#some-button').on('click',function(){
      var modal=$('#single-modal-in-the-page');  
      $.ajax({
        type:"GET",
        url:'http://url/some/create',
        data:{/*any query string paramteres can be set here*/},
        success:function(response){
          modal.find('.modal-body').html(response.html);
          modal.modal('show');
        },
        error:function(error){
          // Or handle the errors in your own way
          console.log(error);
        }

      });    
   });
 });

</script>