Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Laravel 4如何使用ajax和json返回多视图数据?_Php_Jquery_Ajax_Json_Laravel - Fatal编程技术网

Php Laravel 4如何使用ajax和json返回多视图数据?

Php Laravel 4如何使用ajax和json返回多视图数据?,php,jquery,ajax,json,laravel,Php,Jquery,Ajax,Json,Laravel,基本上,我尝试使用以下ajax创建一个弹出窗口: $.ajax({ type: 'GET' url: 'news/read' dataType: 'json' cache: false timeout: 10000 }).done (msg) -> $("article#pop-read").empty().html msg.view processing = false window.history.pushState

基本上,我尝试使用以下ajax创建一个弹出窗口:

$.ajax({
    type: 'GET'
    url: 'news/read'
    dataType: 'json'
    cache: false
    timeout: 10000
}).done (msg) ->
    $("article#pop-read").empty().html msg.view
    processing = false
    window.history.pushState
        path: msg.url
        , "", msg.url
    false
我返回一个视图值,它的url如下:

$data = json_encode(array(
        'view' => View::make('layouts.read'),
    'url' => 'news/read/2013/11/24/test-title-seperate-with-dash'
));
return $data;
这一切都非常有效,除了我无法从laravel获取视图值(它在javascript中返回
Object-Object
)。但是如果我直接像
returnview::make('layouts.read')
那样编写它,它会返回很好的结果。为什么呢

另外(不必回答,不是主要问题),当我使用
pushState
时,浏览器上的后退按钮不起作用,这是一个错误吗?

您可以试试这个

$data = json_encode(array(
    'view' => (String)View::make('layouts.read'),
    'url' => 'news/read/2013/11/24/test-title-seperate-with-dash'
));
return $data;
此外,您还可以使用

View::make('layouts.read')->render();
View::make('layouts.read')->__toString();

另外,
Laravel
出于同样的原因提供了
Response::json()
方法(而不是
json\u encode
)。

好的,谢谢,所有解决方案都有效。现在转到
pushState
问题。知道如何将视图解析为json响应吗?如何使用$('#element').html(data.html)为我的页面中的元素提供视图的html?发布一个问题,给我链接,我会回答,在问题中详细说明。