Laravel 4 how to return multiple data using ajax and json?

Basically I am trying to create a popup using this 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

And I return the value of the view, and it refers to this:

$data = json_encode(array(
        'view' => View::make('layouts.read'),
    'url' => 'news/read/2013/11/24/test-title-seperate-with-dash'
));
return $data;

All this works very well, except that I cannot get the view value from laravel (it returns Object objectin javascript). But he comes back well if I write him directly return View::make('layouts.read'). Why is this?

Additionally (no need to answer, not the main question), the back button in my browser does not work, when I use pushState, is this an error?

+4
source share
1 answer

You can try this

$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_encode).

+13

All Articles