For some reason, in my Laravel 5 application, in one of my functions when I render a view and return it to an AJAX function it is returning as plain text.
I am using the same method in multiple places on my site, but in this 1 call, it seems to be breaking and looks like its rendering in plain text?
Route
Route::prefix('ajax')->group(function(){
Route::prefix('users')->group(function(){
Route::post('/setUserPrimaryImage', 'UserController@ajaxSetPrimaryUserImage');
})
})
Ajax
window.setUserPrimaryImage = function(image_id, user_id, elem){
$.post('/ajax/users/setUserPrimaryImage', {'image_id': image_id, 'user_id': user_id }, function(data){
console.log(data);
});
}
User Controller
public function ajaxSetPrimaryUserImage($request){
//Get the user
$user = User::findOrFail($request->user_id);
//Set the primary image id to this one
$user->primary_photo = $request->image_id;
//Save it
$user->save();
//Return rendered user
return view('pages.user.edit.edit-user-images', compact('user'))->render();
}
pages.user.edit.edit-user-images
<div class="row" id="user-edit-images">
<div class="col-12">
<div class="row">
@foreach($user->photos as $key => $image)
<div class="col-12 col-sm-6 col-lg-4 col-xl-3">
<h1></h1>
</div>
@endforeach
</div>
</div>
</div>
Returned HTML from controller
"
\n
\n
\n
\n 1\n <\/div>\n
\n 2\n <\/div>\n
\n 3\n <\/div>\n <\/div>\n <\/div>\n<\/div>"
It definitely looks like its breaking somewhere to me. Again I am using this exact same method elsewhere in my application and its working fine, this is giving me a headache!
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire