So my simple ajax request is not working on iPhone IOS using Safari. It works on my laptop, on all browsers - including safari.
When I say its not working, I mean that data in the success method is empty, but this shouldn't be the case.
$.ajax({
url: '/ajax-get-video-url-iphone',
type: "post",
data: {
'id' : id, //this is correct, I alert(id) and it shows correct
'_token': $("meta[name=_token]").attr('content') //this is also correct
},
success: function(data){
alert('hello'); // This pops up on the screen
alert(data); // This pops up as nothing, empty but it should be a url
}
});
The code above works completely fine on another device and browser, so I have no idea why this is happening.
EDIT::
This is my backend code, it is in laravel by the way
public function ajaxGetVideoUrlIphone(Request $request)
{
$videoId = $request['id'];
if(Auth::check()){
$user = Auth::user();
$userOwnsVideo = 0;
$shoot = Shoot::where('id',$videoId)->with('users')->get();
if($user->subscribed('main')){
$userOwnsVideo = 1;
}else{
if(!empty($shoot[0]['users']) && count($shoot[0]['users']) > 0){
//this stops the loop once its found the users video
$endForEach = 0;
foreach($shoot[0]['users'] as $userVideo){
if($endForEach == 0){
if($userVideo['pivot']['user_id'] == $user['id']){
$endForEach++;
$userOwnsVideo = 1;
}
}else{
break;
}
}
}
}
if($userOwnsVideo){
$shoot = Shoot::where('id', $videoId)->get();
$url = $shoot[0]['iphone_full'];
}else{
$shoot = Shoot::where('id', $videoId)->get();
$url = $shoot[0]['iphone_trailer'];
}
}else{
$shoot = Shoot::where('id', $videoId)->get();
$url = $shoot[0]['iphone_trailer'];
}
//return 'return from route';
return $url;
}