所以我的简单的ajax请求不适用于使用Safari的iPhone IOS。它适用于我的笔记本电脑,适用于所有浏览器 - 包括safari。
当我说它不起作用时,我的意思是成功方法中的数据是空的,但事实并非如此。
$.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
}
});
上面的代码在其他设备和浏览器上完全正常,所以我不知道为什么会发生这种情况。
修改::
这是我的后端代码,顺便提一下
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;
}