1

It seems my Cordova app can't access my API. It always gives me an error (with fetch() for instance):

"TypeError: Load failed".

I guess this is some specific config thing that I haven't found yet.

I know my Django API works and is accessible from my mobile device (using API Tester for example).
I have followed the steps to allow CORS (CORS_ALLOW_ALL_ORIGINS = True, in settings.py)
Fetching from a swift app works on the same phone.
Fetching a public API doesn't work either with Cordova.
Fetching with Cordova works on my iOS simulator.
I have tried some config modifications in the plist file or config.xml.

I would be glad if someone could help me.
I can provide any additional information one might need to help my case.

3
  • Does this answer your question? Javascript "TypeError: Load Failed" error when calling "fetch" on iOS
    – Eric
    Commented Apr 27, 2023 at 15:22
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
    – Community Bot
    Commented Apr 27, 2023 at 16:12
  • @Eric Sadly no, I already went over this. My API is totally accessible on the same phone inside of Safari, the domain name exists and the server isn't receiving any request, so no cors error (+ I authorized the specific origin in my whitelist, knowing that iOS doesn't like wildcards). Commented Apr 28, 2023 at 6:37

1 Answer 1

1

Here is a solution that worked for me, for anyone that might encounter this problem one day :D

Use the Cordova plugin : cordova-plugin-advanced-http

It provides a native implementation to perform the request, instead of using WebView, which was blocking the request, from what I understand...

The plugin offers the global object "cordova.plugin.http" that you can use to perform the request (check GitHub repo for more information on how to implement it).

Not the answer you're looking for? Browse other questions tagged or ask your own question.