3

After googling couple of hours i have to write that cordova(CLI 5.3.3) apps returns page not found while calling through the jquery AJAX.

I already followed all the steps in whitelist plugin(https://github.com/apache/cordova-plugin-whitelist) but still no luck.

I already include those lines in config.xml

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

Also include CSP like

<meta http-equiv="Content-Security-Policy" content="default-src 'self' https:">

AJAX request like

$.ajax({
                    beforeSend: function() { $.mobile.loading("show"); }, //Show spinner
                    complete: function() { $.mobile.loading("hide"); }, //Hide spinner
                    url: weburl+"lgoin.php",                        
                    data: { email: $("#txtemail").val(), password: $("#txtpassword").val()},
                    type: "POST",                       
                    success: function(data) {                       
                        var response=$.parseJSON(data);                         
                        }                           
                    },                      
                    error: function (jqXHR, exception) {
                        var msg = '';
                        if (jqXHR.status === 0) {
                            msg = 'Not connect.\n Verify Network.';
                        } else if (jqXHR.status == 404) {
                            msg = 'Requested page not found. [404]';
                        } else if (jqXHR.status == 500) {
                            msg = 'Internal Server Error [500].';
                        } else if (exception === 'parsererror') {
                            msg = 'Requested JSON parse failed.';
                        } else if (exception === 'timeout') {
                            msg = 'Time out error.';
                        } else if (exception === 'abort') {
                            msg = 'Ajax request aborted.';
                        } else {
                            msg = 'Uncaught Error.\n' + jqXHR.responseText;
                        }
                        alert(msg);
                    },
                });

AJAX Request always end up with massage in error callback like "Requested page not found. [404]"

Note:-- I already test webservice with Avance REST API extension and works well

Can anybody help me with this issue.

Thanks for your time and consideration in advance. -Naitik

user2617214
  • 161
  • 1
  • 4
  • 13
  • Always 404, or other errors, too? – isherwood Oct 08 '15 at 19:16
  • Maybe your server not public to device can connect to service. You can test by open browser in device and typing url + params and see results. If in browser it working then please check in AndroidManifest.xml file (in Android) and make sure have to app can access via internet. – Hanh Le Oct 09 '15 at 01:44
  • 1
    @usherwood Always 404.Other phonegap apps running on cordova cli 3.8(Older apps with same framework) working perfactly fine on same server.Request takes time so it calling server but always return with 404 though service is exist(Server is running on HTTPS). – user2617214 Oct 09 '15 at 04:16
  • Works well with http services but not with https services – user2617214 Oct 09 '15 at 04:28
  • Maybe your link is incorrect because you spelled login.php wrong – Da Mahdi03 Jun 01 '19 at 21:25

2 Answers2

5

I just added this line in application tag of AndroidManifest.xml

android:usesCleartextTraffic="true" 

and it worked for me

Ahmad Ayyaz
  • 774
  • 8
  • 25
0

Basically, the thing is that you should update cordova-whitelist-plugin.

Plugin can be installed with

cordova plugin add cordova-plugin-whitelist

or by adding

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

to config.xml, and then it is configured with

<allow-navigation href="*" />

in place of the old, <access origin="*" /> tag.

please see here for details.

Community
  • 1
  • 1