4

I've added the CORS headers to my response object on the server and all desktop browsers allow ajax calls to return perfectly. However , i don't see the data coming in on any mobile browser and it turns out its a CORS error

Any ideas why this might happen?

CLIENT CODE:

getCharacter(completionFunc){
        $.ajax("http://somewhere.com/api/character/0", {
            //dataType: 'jsonp',
            success: function(data) {
                completionFunc(data);
            }
        });
    }

SERVER HEADERS CODE (laravel):

 public function handle($request, Closure $next)
    {
        return $next($request)
    ->header("Access-Control-Allow-Origin","*")
    ->header("Access-Control-Allow-Methods","GET, POST, PUT, DELETE, OPTIONS");
    }

Before adding the headers to the server i was getting a cors error on desktop browsers (as expected). Adding them fixed it, but not on mobile. Is there any significant difference between chrome mobile/desktop when it comes to handling CORS? ( i also tried the jsonp dataType on the ajax call but that didnt work)

Return-1
  • 2,329
  • 3
  • 21
  • 56
  • you are _assuming_ or have you tested that there's a CORS error? can you do a test with a mobile device? – Lorenzo Marcon Oct 27 '17 at 08:44
  • 1
    _“Im new in web dev so i don't know **how to debug a mobile web browser** yet”_ - then type the part i highlighted into Google ... https://stackoverflow.com/q/5794984/1427878 – CBroe Oct 27 '17 at 08:46
  • For everyone getting upset about this, i did debug it according to Boratzan and indeed the error is cors related. – Return-1 Oct 27 '17 at 09:46
  • 2
    did you find out why this was happening? Experiencing same issue only on android chrome. – Nigel Jul 11 '19 at 15:37
  • if you are using port forwarding => you need to do port forwarding for your frontend as well as for your backend api. it may not be a cors issue => it could just be that you have not done port forwarding for either your frontend or backend urls – mrtechmaker Aug 12 '21 at 23:50

2 Answers2

0

my luck. I got almost same problem but I had it on desktop's browser instead of mobile. Actually only certain pc that had it. I believe it's about SSL.

nomib
  • 29
  • 6
  • 2
    This does not really answer the question. If you have a different question, you can ask it by clicking [Ask Question](https://stackoverflow.com/questions/ask). To get notified when this question gets new answers, you can [follow this question](https://meta.stackexchange.com/q/345661). Once you have enough [reputation](https://stackoverflow.com/help/whats-reputation), you can also [add a bounty](https://stackoverflow.com/help/privileges/set-bounties) to draw more attention to this question. - [From Review](/review/late-answers/32664885) – klediooo Sep 14 '22 at 08:17
-1

Since we don't now what the actual problem is due the fact that you can't debug, here is an explanation to debug on your phone.

1. Install adb on your computer (if not installed).

Usually installed together with the Android SDK

2. Enable USB debugging on your phone

To use ADB with your device, you must enable USB debugging. Open your phone’s settings, and select about. Tap the field with the build number seven times. You should get a message saying you are now a developer.

Head back to the settings page, and you should see a new option in the bottom called "Developer Options". Now enable "USB Debugging".

Now, when you connect your phone to your computer, you’ll see a popup entitled "Allow USB Debugging?". Check the "Always allow from this computer" and confirm.

3. Test and run ADB

Run the following command in a command prompt window (CMD):

adb devices

You should see your device in the list.

4. Open chrome inspect tab

Now, if all previous steps are done and you successfully run ADB, open chrome in your desktop and go to the following URL:

chrome://inspect

You should see your Phone and the browser running on it, click on the desired instance / website and the developers console will open.

Good luck :) From now on, you can debug on your phone as well. Perhaps you'll find the error there and if you can't manage to solve it, place the actual error here so we can help you further.

Huso
  • 1,501
  • 9
  • 14
  • well i did that and this is the actual error after all. guess not showing the confidence to lie when indeed this was expected to be the error awards me -1. nice. – Return-1 Oct 27 '17 at 09:45
  • Can you share some code so I can see what's going wrong? It's just guessing right now.. – Huso Oct 27 '17 at 10:00
  • added but im afraid its too plain to be of actual help : / – Return-1 Oct 27 '17 at 10:20