Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
490 views
in Technique[技术] by (71.8m points)

javascript - (SOLVED) REST API (http and https) Ajax Call is not working in Latest Cordova Ver 10.0.0

I have developed an application by using Cordova 9.0.0 and it's in production for more than years. Recently a few days back I upgraded my Cordova version from 9.x to 10.x. After the upgrade, Http and Https (REST API) calls are not working in the release build.

Although the API calls are working fine in android debug build, tested on real android device (Realme 3 pro) and in chrome browser.

Since the issue has occurred in the release build I am unable to produce any error log.

I am using AJAX to make API calls.

Note: All REST APIs are Https hosted.

AJAX Call

$.ajax({
    type: "POST",
    url: "https://example.com/methodName",
    data: {
        data: mYData
    },
    contentType: 'application/x-www-form-urlencoded',
    timeout: 30000,
    success: function (data) {},
    error: function (message, textStatus) {}

Related Queries:

  1. Http and Https calls not working after Cordova upgrade
  2. My release apk crash immediately but the debug app work properly ionic 5

EDIT: Below error response is log on API call.

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Posting the solution to my own question for developers facing the same problem and also for my future reference.

Solution

Add the attribute android:usesCleartextTraffic to true in AndroidManifest.xml file inside <application> tag.

Reason

When the attribute is set to "false", platform components (for example, HTTP and FTP stacks, DownloadManager, and MediaPlayer) will refuse the app's requests to use cleartext traffic.

For More detailed Info visit https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...