Support the ongoing development of Laravel.io →
Requests Database Eloquent
Last updated 2 years ago.
0

You could return a HTML view JSON encoded and insert back into the DOM such as

$html = View('admin.comments._comments', $view_data );
return \Response::json(['status' => 'true','html' => $html->render() ]);	

(an example from an admin panel in one of my projects)

else just replace the view with an array of data and insert back into the DOM accordingly.

Hope it helps.

0

jacksoncharles said:

You could return a HTML view JSON encoded and insert back into the DOM such as

$html = View('admin.comments._comments', $view_data ); return \Response::json(['status' => 'true','html' => $html->render() ]); (an example from an admin panel in one of my projects)

else just replace the view with an array of data and insert back into the DOM accordingly.

Hope it helps.

thanks, this works, but i'm not sure of the jQuery part how to I access it in my view?

0

According to your code it will exist in "html"

success: function(html) { 
  console.log(html);
  return $data // ??????
},

So from there you need to insert the HTML into your webpage replacing or appending to whatever DOM element you want.

success: function(html) { 
    if( html['status'] == 'true' )
    {
        $('#some_element').replace(html['html']);
    }
    else
    {
        // Status not equal true, do something else
    }
},

PS> Replace

success: function(html) { 

with something like

success: function(responseData) { 

More conventional and you are not always returning HTML

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.