Ajax cache: false in PhoneGap 2.1 loading error - android

I found that the ajax call loading problem occurs when cache: false is added. I have tested it on three mobile phones: Samsung Galaxy SIII (Android 4.1.2), Sony Xperia P (Android 4.0.4) and LG (Android 4.0.3). Only SIII has no problem. Sony and LG phones just keep loading when calling ajax. How to solve it?
This following code is the ajax call mentioned:
$.ajax({
url: serviceURL ,
async: true,
cache: false,
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({
.......
}),
success: function(data) {
......
}
});
If I removed cache: false, the three phones run the ajax normally.
The mobile app uses PhoneGap 2.1, Backbone.js, Jquerymobile 1.2 and Jquery 1.8.2.

Pages fetched with POST are never cached, so the cache and ifModified options in jQuery.ajaxSetup() have no effect on these requests.

Related

Ionic Android app can't connect to local IP address

I am running my android app with ionic cordova run android, and doing a HTTP get to a local ip address:
this.http.get('http://192.168.2.124:8080')
.pipe(map((response: any) => {
alert(response);
return response;
}),
catchError(map((error: Response | any) => {
alert(error);
console.error('API error: ', error);
return error;
})));
However, nothing happens at all, no errors either.
Note:
replacing the host with something I deployed on the cloud works just fine;
using the phone's web browser to navigate to that endpoint also works.
I'm lost: is there a android or ionic configuration I'm missing to allow this?
Thank you

NetworkError: Failed to execute 'send' on XMLHttpRequest': Failed to load

Server side is Django/python.
Client environment is cordova/android.
This request fails :
$.ajax({
url: myAddress,
type: 'POST',
data: mydata,
crossDomain: true,
processData: false,
contentType: false,
async: false,
success: function () { mycode},
error: function (xhr) { mycode} }
});
When myAddress is 192.168.1.11 it works perfectly.
When myAddress is dev.mysite.com i get the error:
NetworkError: Failed to execute 'send' on XMLHttpRequest': Failed to load dev.mysite.com/../..
However, i can connect to the same django web server with chrome on the mobile device.
config.xml contains : access origin="*"
Do you have an idea to solve this problem?
The js code is good.
The CSP code is good.
My problem came from my misunderstanding of http redirection at the DNS level.
Thank you for you attention

Cordova Hybrid App fails, Legacy Android Build Works

I've written a small application to test the working of cordova app on XDK.
The source code is same as this question
However, I am attaching the code here :
(function()
{
"use strict";
/*
hook up event handlers
*/
function register_event_handlers()
{
/* button Login */
$(document).on("click", ".uib_w_9", function(evt)
{
//intel.xdk.notification.showBusyIndicator();
/*$.post("http://url/test.php", {test:'1'},
function(res){
alert(res);
}
);*/
$.ajax({
beforeSend: function(){
intel.xdk.notification.showBusyIndicator();
},
type: "GET",
url: 'http://url/test.php',
data:{test:'1'},
success: function(res){
alert(res);
intel.xdk.notification.hideBusyIndicator();
},
error:function(res){
alert(res);
intel.xdk.notification.hideBusyIndicator();
},
dataType: 'text'
});
});
}
document.addEventListener("app.Ready", register_event_handlers, false);
})();
This is the JS file of the application.
The screenshot of the app in XDK emulator :
Now When I do a build of the app using XDK cloud, I get a .apk file.
On uploading the file to GenyMotion Emulator, screen below :
The click doesn't do anything, nor does the showBusyIndicator() show, nor the alert appear.
What am I missing and what is going wrong ?
I've plans to use this ide for a proper project and hence the testing, some help will be appreciated.
UPDATE
I did a Cordova Hybrid App build initially and that caused the problem.
When I did a legacy android build, then the problem was solved.
So what do I need to do to get it to work with the Cordova Build ?
Build Page :
There is a known issue with AJAX when Intel XDK builds apk with Cordova CLI version 4.1.2. on Android version > 4.4
There is a workaround, go to Project Settings -> Build Settings -> Android, change Cordova CLI version from 4.1.2 to 3.5 and AJAX should work.

Cordova android app - POST request returns "forbidden access" error

For some reason my Cordova built app cannot send POST requests as a mobile application. If I run it from a browser (in my PC or mobile device) it works fine, but when I run it as mobile app request fails giving 403 forbidden error. Maybe someone has encountered similar problem before and knows what to do?
P.S. GET requests work fine.
config.xml:
<access origin="mytestserver.eu/test"/>
.js:
$.ajax({
type: 'POST',
url: "http://mytestserver.eu/test",
data: '{ "test": "Test"}',
dataType:'json',
headers: {
'Content-Type': 'application/json'
},
crossDomain: true,
success: function(data, textStatus, request){
alert ($.toJSON(data));
},
error: function (request, textStatus, errorThrown) {
alert ($.toJSON(errorThrown));
}
});
This issue was resolved when I disabled ModSecurity on my server.
For me, I was able to do that via the cPanel access to my host:
cPanel > Security > ModSecurity

Failed on using Sencha Touch to package a very simple native app for android

I am learning how to develop app with Sencha Touch. When I try to package a very simple app to run on android emulator, I failed. The screen just got stuck on dots keep blinking.
All I did is create a new project using Secha CMD, and then replace the content of app.js with the following:
Ext.application({
name: 'Sencha',
launch: function() {
Ext.create("Ext.tab.Panel", {
fullscreen: true,
tabBarPosition: 'bottom',
items: [
{
title: 'Home',
iconCls: 'home',
html: [
'<img src="http://staging.sencha.com/img/sencha.png" />',
'<h1>Welcome to Sencha Touch</h1>',
"<p>You're creating the Getting Started app. This demonstrates how ",
"to use tabs, lists, and forms to create a simple app</p>",
'<h2>Sencha Touch</h2>'
].join("")
}
]
});
}
});
I am using Sencha Cmd v4.0.0.203, ruby 1.9.3p448, windows 8
My app works fine when I test it on my PC using IIS as a web server, no errors.
I found a similar thread here:
http://www.sencha.com/forum/showthread.php?238441-App-hangs-at-three-dots-blinking-screen
but the solution mentioned in this thread does't work for me.
You have to allow access to external domains in your config.xml:
<access origin="*"/>

Categories

Resources