Mobile Apps: Data blocked by CORS?

Trying to add data to a mobile app and the data does not load. I get the following error.

Access to XMLHttpRequest at 'https://mysite.com/dmxConnect/api/jobs/lists/locationlist.php?’ from origin ‘http://localhost:12345’ has been blocked by CORS policy: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.

What does that mean and how do I fix it?

Well you just need to enable CORS in your server connect project in its options.

2 Likes

I’m not sure how you have set up things for Mac but another thing you can try is to go to the plugins directory and delete:

cordova.plugin-whitelist

Then rebuild your Project, this directory and plugin will be reinstated, then try again and see if you still have the CORS issue Brad. It is a known issue with this plugin. Especially if you have made changes to the App Info section, Title, Description, Version, ID, etc.

A good tip for the ID. This helps with your Play Store listing so be thoughtful in naming it.

Example: app.CarSalvagePeckam.London

If you have changed the app ID it is definitely worth deleting the whitelist plugin directory as mentioned above. Changing the version identifier does not require this. Simple heads-up to a problem we have encountered…

I looked everywhere. Where do you do that?

Edit: Found it!

That didn’t work. Is there a file that needs to be uploaded to the live server after changing that setting?

Did a full publish and now my data works. Thanks for your help.

Helpful diagnosis for CORS issues updated:

Report CORS errors in the Network panel

DevTools now shows CORS error when a network request is failed due to Cross-origin Resource Sharing (CORS).

In the Network panel, observe the failed CORS network request. The status column shows “CORS error” . Hover over on the error, the tooltip now shows the error code. Previously, DevTools only showed generic “(failed)” status for CORS errors.

This lays the foundation for our next enhancements on providing more detailed description of the CORS problems!

What exactly needs to be specified as Origin?
I see it updated the config.php file and published it but still same CORS error.
image

Exactly what you have should work. That’s what mine is set at.

1 Like

Indeed, works as is.
… and after I redid my submit form request.

1 Like