Php 将视图返回到ajax请求

Php 将视图返回到ajax请求,php,ajax,laravel-5.4,Php,Ajax,Laravel 5.4,我正在使用Laravel54。我正在尝试使用ajax请求显示表单。 我返回一个json响应,但是java脚本中接收到的数据是一个包含两个对象的字符串 我的行动 public function edit($product) { $product = Product::where(['id'=>$product])->get(); $categories=Category::orderBy('name')->get(); va

我正在使用Laravel54。我正在尝试使用ajax请求显示表单。 我返回一个json响应,但是java脚本中接收到的数据是一个包含两个对象的字符串

我的行动

public function edit($product)
    {
        $product = Product::where(['id'=>$product])->get();
        $categories=Category::orderBy('name')->get();
        var_dump($categories);
        $view=view('product.manage',compact('categories','product'));
        $html=$view->render();
        return response()->json(['success'=>true,'html'=>$html]);
    }
java脚本代码

$(document).on('click','.edit-product',function(e){
    e.preventDefault();
    var url=$(this).attr('href');
    $.ajax({
        url:url,
        type:'get',
        success:function(response){
            $('#data-holder').html(response.html);
        },
        error:function(e){
            alert(e);
        }
    });
java脚本中的响应变量为:

"object(Illuminate\Database\Eloquent\Collection)#212 (1) {
  ["items":protected]=>
  array(8) {
    [0]=>
    object(App\Category)#213 (24) {
      ["connection":protected]=>
      string(5) "mysql"
      ["table":protected]=>
      NULL
      ["primaryKey":protected]=>
      string(2) "id"
      ["keyType":protected]=>
      string(3) "int"
      ["incrementing"]=>
      bool(true)
      ["with":protected]=>
      array(0) {
      }
      ["perPage":protected]=>
      int(15)
      ["exists"]=>
      bool(true)
      ["wasRecentlyCreated"]=>
      bool(false)
      ["attributes":protected]=>
      array(2) {
        ["id"]=>
        int(5)
        ["name"]=>
        string(15) "Beauty & Health"
        //................................
      }
    }
  }
}
{"success":true,"html":"<div class=\"container\">\n    <div class=\"row\">\n    //...........    \n    <\/div>\n<\/div>"}"
“对象(照亮\数据库\雄辩\收集)#212(1){
[“项目”:受保护]=>
阵列(8){
[0]=>
对象(应用程序\类别)#213(24){
[“连接”:受保护]=>
字符串(5)“mysql”
[“表”:受保护]=>
无效的
[“primaryKey”:受保护]=>
字符串(2)“id”
[“密钥类型”:受保护]=>
字符串(3)“int”
[“递增”]=>
布尔(真)
[“带”:受保护]=>
数组(0){
}
[“每页”:受保护]=>
内部(15)
[“存在”]=>
布尔(真)
[“wasnrecentlycreated”]=>
布尔(假)
[“属性”:受保护]=>
阵列(2){
[“id”]=>
内部(5)
[“名称”]=>
字符串(15)“美容与健康”
//................................
}
}
}
}
{“success”:true,“html”:“\n\n/………\n\n”}”

如何访问返回的视图html?

删除
var\u dump($categories)部分,因为该部分打印对象的内容

删除
var\u dump($categories)部分,因为该部分打印对象的内容

larvel默认情况下渲染局部。您正在调用
View::make()
,并将渲染视图返回到默认情况下渲染部分的
$html

Laravel。您正在调用
View::make()
并将呈现的视图返回到
$html

var\u dump($categories)?:)<代码>变量转储($categories)?:)