App not transfering data to db on local server after phonegap build

Dear all,
I have created an app which when deployed to PC local folder (192.168.1.9) and run using Apache server, behaves as expected in the sense that it stores data to a MySql database (running on the same PC) when accessed by phone (192.168.1.4).
When I deploy the app using phonegap, I cannot communicate with the server. I am not sure of the error because I do not get back an error message, but the record is not inserted into database.
If I look at the success message returned to Ajax call, I see the whole php code executed.

Any help appreciated.

Sounds like it could be a CORS issue.

You should be able to open the Chrome Remote Debugger and look at your PhoneGap App while it is connected to your device by a USB cable.

Look for error messages in the Console.

This blog post has a bit more information:
https://blog.appstudio.dev/2015/12/phonegap-no-content-security-policy-message/

Share your story with the AppStudio Community! Quarantine Stories

Dear George,
Thank you very much for your reply especially during this hard times!
Please note that the only messages received in debug console (Chrome) during execution is:
“Could not find cordova.js script tag. Plugin loading may fail.”

I am not sure that this has anything to do with CORS but again I am not sure 100%.

I also get 2 Warnings:
a. DevTools failed to parse SourceMap: file:///android_asset/www/toolbox/bs4/dist/js/bootstrap.bundle.min.js.map

b. DevTools failed to parse SourceMap: file:///android_asset/www/toolbox/bs4/dist/css/bootstrap.min.css.map

Do you think I am missing something?

Those messages can all be ignored. The cordova script tag isn’t needed, so it doesn’t matter that it isn’t there. The other two messages are common:
https://wiki.appstudio.dev/Solutions_to_Common_Problems#.22Chrome_can.E2.80.99t_find_.2A.min.map.22

When you are running locally, the app and the database are on the same server, so there are no CORS issues. When you’re running on a device, you’re at a different location, which is why I think that’s a likely explanation. Is the Ajax call returning a success message? What do the logs on the server say is happening?

I see you’re in Greece. How are things there? Tell us all in Quarantine Stories - #15 by GaryGorsline!

I have made a mistake on my story.
I inserted the php file inside my project (in AppStudio files) so I wasn’t calling the php file from the www of the server but from my mob phone.
Nevertheless still, after changing my Ajax call to triger the correct .php (register.php) file on the server, using :192.168.1.9/site1/register.php, I get the followign error: file:///android_asset/www/192.168.1.9/househeatingcontrol/register.php net::ERR_FILE_NOT_FOUND

    $.ajax({
            type: "POST",
            url: "192.168.1.9/site1/register.php",
            data:strData,
            crossDomain: true,
            cache: false,
            success: function(d){
            if (d == 'This email is already being used') {
             alert ("The email is already being used. New account with existing email cannot be created.")
             return true;
            }
            alert("Thank you for registering!");
            alert (d);
            },
            error: function(e) {
            alert (e)
            alert("An error has occured. Please contact reseller.")
      }
       });
        }

I think we are very close to nailing down the problem. The register.php is not found (although existing in www/site1/ but phonegap is asking for android_asset/www/192.168.1.9/site1/register.php. How can I direct the app to ask for this specific file on the server and not localy?

I will post a situation on Greece! Just a hint: Coronavirus is sending a global message: We should promote solidarity in the society in order to survive. Nature is above all markets. Lets hope this message will reach the ones taking decisions…

192.168.1.9 is a local address on your computer. It’s not one which can be used by an app running on another system (which is a good thing, otherwise, everyone could add records to your database).

You’ll need to set up a proper web server on your computer which can handle requests from other systems.

1 Like

When running on mob phone through Chrome, the mob phone having an IP: 192.168.1.3, is communicating with the server on 192.168.1.9. So, I thought that I have set up WAMP server properly. I have also managed to do so externally via port forward. I managed to reach the server from my mob phone when it is connected via 4G (externally). I cannot imagine why WAMP is not configured properly to accept Ajax from phoneGap…

Dear George,

I have found the solution after posting to (javascript - Communicate with local server from a mobile in the same network through a phonegap app - Stack Overflow).

The problem was that I didn’t declare the protocol (http): http://192.168.1.9/site1/register.php

Thank again !