0

I am developing Phonegap app in which I am accessing a database hosted on another server with ajax calls. its working fine in local, but when I make APK and run that app it generates 404 Error.

Error:

POST http://mywebsite.com/mobileapp/function.php 404 (Not Found)**

App html File:

<html>
<head>
    <meta charset="utf-8" />
    <meta name="format-detection" content="telephone=no" />
    <meta name="msapplication-tap-highlight" content="no" />
    <!-- WARNING: for iOS 7, remove the width=device-width and height=device-height attributes. See https://issues.apache.org/jira/browse/CB-4323 -->
    <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline' 'unsafe-eval'">
    <script src="js/jquery-2.2.0.min.js" type="text/javascript"></script>
</head>
<body>
    <div id="container">
<p><span id="usermessage" style="color: red; font-weight: bold;"></span></p>
        <div id="formdiv">
            <form action="#" method="post" >
                <p> <input type="text" name="username" id="username" placeholder="Enter Usernam" ></p>

                <p> <input type="password" name="password" id="password" placeholder="Enter Password"></p>
                <p> <input type="button" id="submit" value="Login" class="button" ></p>
            </form>
        </div>
    </div>
    <script type="text/javascript">
        $(document).ready(function ()
        {
            $("#submit").click(function () {
                $("#submit").css("background-color", "red");
                var un = $("#username").val();
                var pass = $("#password").val();
                var status = "login";
                if (un == '' || pass == '')
                {
                    $("#usermessage").text("Please Enter Username and Password");
                }
                else {
                    $("#usermessage").text("Else");

                    $.ajax({
                            type: 'POST',
                            dataType: 'json',
                            data: "username="+un+"&password="+pass+"&status="+status,
                            url: 'http://mywebsite.com/mobileapp/function.php',
                            crossDomain: true,
                            cache: false,
                            success: function(data){
                             console.log(data.ID);
                             $("#submit").css("background-color", "green");
                             $("#usermessage").text("Login Successful");
                            },
                            error: function(data){
                                    console.log(data);
                             $("#submit").css("background-color", "black");
                            }
                    });
                }
            });

        });
    </script>

    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript" src="js/index.js"></script>
    <script type="text/javascript">
        app.initialize();
    </script>
</body>

App config.xml file

<widget xmlns="http://www.w3.org/ns/widgets" xmlns:gap="http://phonegap.com/ns/1.0" id="com.phonegap.helloworld" version="1.0.0">
<name>mywebsite</name>
<description>testetstesetst</description>
<author href="http://mywebsite.com" email="support@mywebsite.com">mywebsite Team</author>
<content src="index.html"/>
<preference name="permissions" value="none"/>
<preference name="orientation" value="default"/>
<preference name="target-device" value="universal"/>
<preference name="fullscreen" value="true"/>
<preference name="webviewbounce" value="true"/>
<preference name="prerendered-icon" value="true"/>
<preference name="stay-in-webview" value="false"/>
<preference name="ios-statusbarstyle" value="black-opaque"/>
<preference name="detect-data-types" value="true"/>
<preference name="exit-on-suspend" value="false"/>
<preference name="show-splash-screen-spinner" value="true"/>
<preference name="auto-hide-splash-screen" value="true"/>
<preference name="disable-cursor" value="false"/>
<preference name="android-minSdkVersion" value="14"/>
<preference name="android-installLocation" value="auto"/>
<gap:plugin name="org.apache.cordova.media-capture"/>
<gap:plugin name="org.apache.cordova.console"/>
<gap:plugin name="org.apache.cordova.device"/>
<gap:plugin name="org.apache.cordova.device-motion"/>
<gap:plugin name="org.apache.cordova.device-orientation"/>
<gap:plugin name="org.apache.cordova.dialogs"/>
<gap:plugin name="org.apache.cordova.file"/>
<gap:plugin name="org.apache.cordova.file-transfer"/>
<gap:plugin name="org.apache.cordova.geolocation"/>
<gap:plugin name="org.apache.cordova.globalization"/>
<gap:plugin name="org.apache.cordova.inappbrowser"/>
<gap:plugin name="org.apache.cordova.media"/>
<gap:plugin name="org.apache.cordova.network-information"/>
<gap:plugin name="org.apache.cordova.splashscreen"/>
<gap:plugin name="org.apache.cordova.vibration"/>
<gap:plugin name="cordova-plugin-whitelist" version="1.0.0" source="npm" />
<icon src="icon.png"/>
<icon src="www/res/icon/android/icon-36-ldpi.png" gap:platform="android" gap:qualifier="ldpi"/>
<icon src="www/res/icon/android/icon-48-mdpi.png" gap:platform="android" gap:qualifier="mdpi"/>
<icon src="www/res/icon/android/icon-72-hdpi.png" gap:platform="android" gap:qualifier="hdpi"/>
<icon src="www/res/icon/android/icon-96-xhdpi.png" gap:platform="android" gap:qualifier="xhdpi"/>
<icon src="www/res/icon/blackberry/icon-80.png" gap:platform="blackberry"/>
<icon src="www/res/icon/blackberry/icon-80.png" gap:platform="blackberry" gap:state="hover"/>
<icon src="www/res/icon/ios/icon-57.png" gap:platform="ios" width="57" height="57"/>
<icon src="www/res/icon/ios/icon-72.png" gap:platform="ios" width="72" height="72"/>
<icon src="www/res/icon/ios/icon-57-2x.png" gap:platform="ios" width="114" height="114"/>
<icon src="www/res/icon/ios/icon-72-2x.png" gap:platform="ios" width="144" height="144"/>
<icon src="www/res/icon/webos/icon-64.png" gap:platform="webos"/>
<icon src="www/res/icon/windows-phone/icon-48.png" gap:platform="winphone"/>
<icon src="www/res/icon/windows-phone/icon-173-tile.png" gap:platform="winphone" gap:role="background"/>
<gap:splash src="www/res/screen/android/screen-ldpi-portrait.png" gap:platform="android" gap:qualifier="port-ldpi"/>
<gap:splash src="www/res/screen/android/screen-mdpi-portrait.png" gap:platform="android" gap:qualifier="port-mdpi"/>
<gap:splash src="www/res/screen/android/screen-hdpi-portrait.png" gap:platform="android" gap:qualifier="port-hdpi"/>
<gap:splash src="www/res/screen/android/screen-xhdpi-portrait.png" gap:platform="android" gap:qualifier="port-xhdpi"/>
<gap:splash src="www/res/screen/blackberry/screen-225.png" gap:platform="blackberry"/>
<gap:splash src="www/res/screen/ios/screen-iphone-portrait.png" gap:platform="ios" width="320" height="480"/>
<gap:splash src="www/res/screen/ios/screen-iphone-portrait-2x.png" gap:platform="ios" width="640" height="960"/>
<gap:splash src="www/res/screen/ios/screen-iphone-portrait-568h-2x.png" gap:platform="ios" width="640" height="1136"/>
<gap:splash src="www/res/screen/ios/screen-ipad-portrait.png" gap:platform="ios" width="768" height="1024"/>
<gap:splash src="www/res/screen/ios/screen-ipad-landscape.png" gap:platform="ios" width="1024" height="768"/>
<gap:splash src="www/res/screen/windows-phone/screen-portrait.jpg" gap:platform="winphone"/>
<access origin="http://mywebsite.com"/>
<allow-navigation href="http://mywebsite.com/*" />
<allow-intent href="http://mywebsite.com/*"/>
<allow-intent href="https://*/*"/>
<allow-intent href="tel:*"/>
<allow-intent href="sms:*"/>
<allow-intent href="mailto:*"/>
<allow-intent href="geo:*"/>
<platform name="android">
<allow-intent href="market:*"/>
</platform>
<platform name="ios">
<allow-intent href="itms:*"/>
<allow-intent href="itms-apps:*"/>
</platform>
</widget>
Waqar ahmad
  • 139
  • 11

1 Answers1

1

NOTE TO ALL: This app use an unrestricted whitelist filter - intended for development only.
THIS APP EXAMPLE IS INSECURE. IT IS UP TO YOU TO SECURE YOUR APP.
In addition, your app maybe reject by Google and Apple.


I'm clueless, but maybe you have not the right cordova-plugin-whitelist

You are currently using

<plugin name="com.indigoway.cordova.whitelist.whitelistplugin" source="pgb" />

I think you need to change that

try: cordova plugin add cordova-plugin-whitelist

or in your config.xml file :

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

but if you are using the online phonegap build service the syntax is different. You have to add the following line in your config.xml file :

<gap:plugin name="cordova-plugin-whitelist" source="npm" />

and authorize cross domain requests :

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

All Credits go to: Phonegap Cordova Ajax requests 404 (Not Found) Error

and here: Ajax Command to request URL no longer working

Community
  • 1
  • 1