How can I return a view from an AJAX call in Laravel 5?
The view()
function just creates an instance of the View
class. Not just an HTML string. For that you should call render()
:
$returnHTML = view('job.userjobs')->with('userjobs', $userjobs)->render();
return response()->json(array('success' => true, 'html'=>$returnHTML));
if your ajax is correct and you are getting results from your DB
$returnHTML = view('job.userjobs',[' userjobs'=> $userjobs])->render();// or method that you prefere to return data + RENDER is the key here
return response()->json( array('success' => true, 'html'=>$returnHTML) );
use string function before view file name like as
return (String) view('Company.allUserAjax');