Question
Problem with ajax on server (in localhost is good)
Hello, I have a ajax in my localhost and is working good, but when I put it in the dopplet no is working. Any block? I must config anything more?
My ajax:
$.ajax({
type: "post",
url: url,
data: {"_token": "{{ csrf_token() }}",
year: year, index: index
},
success: function(data) {
$.each(data,function(key,value){
var oBox=$('<div>').addClass('box').appendTo($('#gallery'));
var oPic=$('<div>').addClass('pic').appendTo(oBox);
$('<img>').attr('src', $(value).attr('src')).appendTo(oPic);
});
My Laravel controller:
public function gallery(Request $request)
{
$json = Photo::where('year', '=', $request->year)->skip(20 * $request->index)->take(20)->get();
if (!$json->isEmpty()) {
foreach ($json as $data)
{
$elements[] = ['src' => '../img/gallery/'.$data->year.'/'.$data->filename.'.'.$data->extension, 'download' => '../img/gallery/'.$data->year.'/download/'.$data->filename.'.'.$data->extension];
}
$json = response()->json($elements);
}
return $json;
}
These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.
×