jquery - Error in Accessing exrenal database file using ajax call in Phonegap app -


i developing phonegap app in accessing database hosted on server ajax calls. working fine in local, when make apk , run app 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: ios 7, remove width=device-width , 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 , 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> 

note all: app use unrestricted whitelist filter - intended development only.
this app example insecure. secure app.
in addition, app maybe reject google , apple.


i'm clueless, maybe have not right cordova-plugin-whitelist

you using

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

i think need change that

try: cordova plugin add cordova-plugin-whitelist

or in config.xml file :

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

but if using online phonegap build service syntax different. have add following line in 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 request url no longer working


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -