Troubleshooting AJAX failures in Android Cordova app's Release mode

Encountering an issue with AJAX calls failing in release mode on Android but working fine on iOS. The error message seen in Chrome Dev Tools is:

Provisional headers are shown

Request URL:https://server.com/api/index.php?ticket=ST-111111-ABCDEFG-cas

Request Headers
Provisional headers are shown
Content-Type:application/x-www-form-urlencoded; charset=UTF-8
Origin:file://
User-Agent:Mozilla/5.0 (Linux; Android 6.0; Google Nexus 5 - 6.0.0 - API 23 - 1080x1920 Build/MRA58K) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/40.0.0.0 Mobile Safari/537.36
Query String Parametersview sourceview URL encoded
ticket:ST-111111-ABCDEFG-cas

Form Dataview sourceview URL encoded
request:{"param1":"val1","param2":"val2"}

The issue persists when running the app in Debug mode and even after updating Cordova to the latest version. Current tool versions include:

Config.xml settings include:

<allow-navigation href="*" />
<access origin="*" />
<allow-intent href="*" />

Whitelist plugin being used:

<plugin name="cordova-plugin-whitelist" spec="1" />

Additionally, a meta tag has been set in the index.html file:

<meta http-equiv="Content-Security-Policy" content="default-src *; img-src 'self' data:; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">

Any other important Cordova settings that might have been missed?

Tried removing and re-adding Android platform, as well as updating all plugins but still facing the same Ajax error.

Your assistance would be greatly appreciated.

Answer №1

Encountered a similar issue where $.ajax was functioning correctly in the debug version but failing with status code 0 in the release version. The root cause was found to be an expired SSL certificate. By switching from https to http, the problem was resolved and the release version worked smoothly as well. For more details, refer to this link:

Answer №2

Developers working with APIs must enable cross-origin headers.

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: CUSTOM_HEADERS);
header('Access-Control-Allow-Methods: POST, GET, PUT, DELETE, OPTIONS);

Additionally, when a request is made from Cordova or via AJAX, there are two AJAX calls: the first call is for options, where the API only returns allowed headers & methods, and then the second call is the actual API call being made.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Generating Regular Expressions for Javascript Validation

I'm struggling to come up with the correct regular expression for validating input. It seems like it should be simple, but I'm still encountering a few issues. The desired input format should be: "tests.xxxxxxx" where the x's can be any alp ...

Refresh the webpage excluding a single element using AJAX

I'm facing a challenge with an audioplayer on a webpage that needs to keep playing without interruption while navigating. The layout of the page cannot be changed, so simply moving the audio player outside and reloading the content is not an option. ...

Upload files with either a Flash or AJAX uploader

When deciding between an AJAX or JQuery upload plugin versus a Flash upload plugin for browser uploads, it's important to consider the differences, especially when dealing with very large files (1-2GB). Is there a specific advantage to choosing one ov ...

Unable to delete cookies that have been created through PHP

Let me explain how I handle cookies using PHP and Javascript. Firstly, in PHP, I create a cookie before the page is loaded using the following code: setcookie('my_key', $value, 0, ADMIN_COOKIE_PATH); For the Javascript part, I utilize jQuery a ...

Failed to transfer form data to server using ajax in Node.js

I am attempting to utilize AJAX to send form data to a Node.js server. I had previously inquired about this on the following post. Below is a glimpse of my code: <div id="inputid" style="width: 400px; height:400px"> <p> Kindly input value ...

Steps to hide a div after it has been displayed once during a user's session

After a successful login, I have a div that displays a success message and then hides after 4 seconds using the following JavaScript code: document.getElementById('success').style.display = 'none'; }, 4000); While this functionality wo ...

Expanding the Element prototype with TypeScript

Is there a corresponding TypeScript code to achieve the same functionality as the provided JavaScript snippet below? I am looking to extend the prototype of the HTML DOM element, but I'm struggling to write TypeScript code that accomplishes this with ...

What could be the reason for Sequelize to completely replace the record when updating in a put request?

I've been attempting to implement an "edit" feature within my project, but I've hit a roadblock in the process. Here's a snippet of the put request code: export const updateEvent = (event, id) => (dispatch, getState) => { request ...

startReactApplication throws an error if executed within AsyncTask in React Native for Android

Encountering the mysterious error message: java.lang.AssertionError: Attached DialogModule to host with pending alert but no FragmentManager (not attached to an Activity). In my MainActivity, I have implemented the following code snippet: @Override prote ...

Loop through each object in the array and create a new property by applying a regular expression to an existing property

Just starting out with Javascript and could use some guidance. Here is an array of objects that I have: var data = [{ name: 'name1', street: 'street2', person: 'person1', phone1: 'phone82 ', phone2: 'phone ...

What is the best way to implement this code using MongoDB's $push and $inc operators?

Having some trouble getting this code to work properly where I use $inc to increase the number of likes and $push to add the userId to the usersLiked array: Sauce.updateOne( { _id: req.params.id }, { ...sauceObject, likes: req.body.like ...

Effective use of dp sizing in LinearLayout for Android development

Wanting to incorporate centered elements into a LinearLayout, such as textViews or buttons, has led me to consider the issue of screen size variability. Specifically, when using android:layout_width="fill_parent", there is concern that on larger screens li ...

Design a dynamic backdrop using three.js

Hey, I'm currently working on incorporating a background image into my Three JS project. Although the code is functioning properly, the background isn't being displayed. Here is my init function: function init(){ // Creating a new scene scene ...

What is the best way to showcase specific information from a JSON file with the help of

Our corporation is looking to showcase job listings that we promote on a prominent job platform. They provide us with JSON data so we can exhibit our company's job openings on our website. I aim to present essential information in a summary format, w ...

The absence or inaccuracy of CSRF token in Django, Django REST Framework, and Internet Explorer

Our Django App uses REST Framework in a setup with nginx, redis, celery, gunicorn, and PostgreSQL. The system consists of only one App server. For ajax calls, we utilize the following function : $.ajaxSetup({ beforeSend: function (jqXHR, settings) { ...

Using JavaScript to transfer HTML entities as a function parameter

Is it possible to pass HTML entities as function parameters in JavaScript? I am developing a React application and I need to transmit HTML entities from the parent component to the child component as a property, and then exhibit the character represented ...

Undefined result when performing an Ajax post

I'm attempting to use ajax to send the value of what is in the div's contents on a post. Specifically, I want to send the content of the div slick-active. In this example, console.log(data.results); would display 4 and 6. Below is the HTML code ...

Fix scrolling problem in the single item view of listview upgrade

I'm having a bit of trouble articulating this issue, so please bear with me. Each list item in my ListView contains a progress bar to show downloading status. I've implemented a mechanism where a specific view is passed to an AsyncTask to update ...

Django has a tendency to run view functions repeatedly after a form submission, even if the client has only submitted the form

I am facing an issue with uploading a user's image to the server in Django (version 1.8) for processing. Despite ensuring that the client only submits the form once, the backend seems to execute the related view function multiple times, leading to a 5 ...

Why does req.body not capture the value of the <textarea> in a Node.js Express application?

I am currently developing a Node.js express app and encountering an issue with my HTML form (inputForm.html): <form action="/" method="post"> Name: <br> <input type="text" name="name" size="45"> <br> Document: <br> ...