php CodeIgniter 4使用来自控制器的视图填充div

2ic8powd  于 2023-05-05  发布在  PHP
关注(0)|答案(1)|浏览(154)

我想从我的控制器中填充一个div,它用 AJAX 为我的onchange调用,但我不能让它工作,我想问题出在我调用的控制器中的函数中。
我尝试使用返回视图,但没有任何效果,我尝试使用setBody,但它不能为表提供循环。
下面是我想填写的div

  1. <div id="tableCont"></div>

下面是我的myscript.js中的脚本:

  1. function call_user_menu ()
  2. {
  3. $.ajax({
  4. type: 'GET',
  5. url: 'http://localhost:8080/menumanagement/formMenuUser',
  6. dataType: 'html',
  7. success: function (html) {
  8. $("#tableCont").empty();
  9. $("#tableCont").html(html);
  10. },
  11. error: function(){
  12. Swal.fire({
  13. title: 'Menu Data failed to load!',
  14. text: "",
  15. icon: 'warning',
  16. confirmButtonColor: '#d33',
  17. cancelButtonColor: '#d33',
  18. })
  19. },
  20. });
  21. }

下面是我在Controller中的函数:

  1. public function formMenuUser()
  2. {
  3. //the default return view :
  4. return view('menu_form-menu-user.php');
  5. //what should I write here to call the view to fill the div?
  6. //can I use the setBody? but I can't use my foreach there
  7. }

我真的很感激任何可以提供的帮助。谢谢

mm5n2pyu

mm5n2pyu1#

你应该像这样穿过风景。

  1. $html = view('menu_form-menu-user')->render();
  2. return $this->response->setBody($html);

阅读-处理响应

相关问题