I'm having an issue passing data from controller to a view loaded via ajax. Below is my code:
JS:
function editass(id, name, title) {
var modal_title = document.getElementById("modal-title");
var modal_name = document.getElementById("modal-name");
var modal_body = document.getElementById("modal-body");
modal_title.innerHTML=title;
modal_name.innerHTML=name;
modal_body.innerHTML = '<div class = "text-info" align="center">Just a moment...</div>';
$("#modal-body").load('/SchoolSmart/public/assessments/edit/'+id);
//alert("modal");
}
Routes:
Route::get('/assessments/edit/{id}', 'AssessmentsController@edit');
Controller function
public function edit($id)
{
$editassessments = Assessment::findOrFail($id);
return view('assessments.edit')->with('$editassessments', $editassessments);
}
View
Assessment name: {!! $editassessments->name !!}
The error returned from the header is: Undefined variable: editassessments
The view loads fine if I remove the call to variable, which is the whole essence of the page. Also, this function works fine if I the view was not loaded via AJAX.
Please, help on how I pass the variable from controller to view loaded via AJAX. Thank you