1

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;
}
virepo
  • 320
  • 5
  • 22
  • is `data` a string? maybe you could try it with `alert(JSON.stringify(data))` – webdeb Jul 13 '16 at 18:40
  • yes it is, i will try it now – virepo Jul 13 '16 at 18:41
  • that displays just "" – virepo Jul 13 '16 at 18:42
  • the server is for whatever reason returning nothing on this request. Showing that code would be relevant to the issue at hand. – rlemon Jul 13 '16 at 18:43
  • @webdeb Don't suggest using `alert()` for debugging purposes. Certain browsers have different levels of lockouts. `console.log()` is the proper tool for the job. – Trasiva Jul 13 '16 at 18:45
  • i have added my server code @rlemon – virepo Jul 13 '16 at 18:46
  • and @trasiva console.log isnt doing anything, which is why im using alert(). I have plugged iphone into mac, and using the inspector it doesnt do any logs to console – virepo Jul 13 '16 at 18:46
  • @Trasiva, but it seems to be a simple way, regarding what he already did, and debugging on an iphone.. well, how should `console.log` work? – webdeb Jul 13 '16 at 18:47
  • @webdeb console.log works fine on an iphone... – Naftali Jul 13 '16 at 18:48
  • If it is reaching the success callback and `data` is empty, then the server isn't sending any data. debug on the server to see why. – Kevin B Jul 13 '16 at 18:48
  • can you try with a simple string as response in your server code, to make sure your iphone gets at least the right response? – webdeb Jul 13 '16 at 18:48
  • 1
    log the url before returning it on the server. see what gets set. also check that your array is actually populated. – rlemon Jul 13 '16 at 18:49
  • when i return a simple string it works, but i dont understand , my backend code works on other devices, so why wouldnt it work on iphone? – virepo Jul 13 '16 at 18:49
  • my guess is the auth fails for ios only and the failing video isn't populated in the array. but that is just a wild guess. – rlemon Jul 13 '16 at 18:50
  • @Neal true, here is a link for howto: http://stackoverflow.com/questions/4478271/remote-console-log-on-ios-devices – webdeb Jul 13 '16 at 18:53

0 Answers0