1

My code works on the web browser, but when I deploy it on Phonegap Android Build, it doesn't work. Anybody here know how to do this? I am using PHP as my backend.

 $$('form.ajax-submit-onchange').on('submitted', function (e) {
   var formData = myApp.formToJSON('form.ajax-submit-onchange');
   var fullname = JSON.stringify(formData.name);
   var gender = JSON.stringify(formData.gender);
   var email = JSON.stringify(formData.email);
   var url = 'http://localhost/androidapi/public/insertuser';
   console.log(url);
   $$.get(url + '/'+fullname+ '/'+email+ '/'+gender, function (data) {
          console.log(data + 'success');
   });
 });
Auromius
  • 49
  • 8
  • In what way does it not work? Is it not sending the request at all? Or is the PHP not responding the way you expect? How are you checking if it's returning the correct data? (I don't use phonegap so I don't know if you can check the console.log) – jonhopkins Oct 05 '16 at 16:53
  • in web browser it is inserting data but in mobile build phonegap desktop app it does not I check the build logs and the console.log(url); is outputting except the console.log(data + 'success'); which means it does not go to the $$get ajax request – Edyl I. Templado Oct 05 '16 at 16:56
  • 1
    Inserting data should probably be using a POST instead of GET. But aside from that, I think it might have to do with the url using localhost. Unless you have the server running on the phone, your "localhost" is located on the computer, and the phone will not be able to connect to it directly. You might have to set it up as a public (at least for your network) server so that the phone has somewhere to connect. How to do that, I don't know. Hopefully someone else can respond with an answer. I'll be sticking around for that because it would be useful to me too. – jonhopkins Oct 05 '16 at 17:01
  • hope someone solved this case already – Edyl I. Templado Oct 05 '16 at 17:12
  • Hi sir I solved it already – Edyl I. Templado Oct 05 '16 at 17:42
  • This is my reference http://stackoverflow.com/questions/32951753/ionic-access-control-allow-origin – Edyl I. Templado Oct 05 '16 at 17:42
  • 1
    all I did is change the localhost IP as you mentioned to my computers ip address var url = 'http://localhost/androidapi/public/insertuser'; to var url = 'http://192.168.1.2/androidapi/public/insertuser'; anyways thanks for your clue. – Edyl I. Templado Oct 05 '16 at 17:43
  • You could make that into an answer and post it below. Comments can be deleted without warning, and your answer might help someone else in the future. – jonhopkins Oct 05 '16 at 17:46

1 Answers1

1

To solve this, all I did is change "localhost" in the URL to my computers IP address.

var url = 'localhost/androidapi/public/insertuser';

was changed to

var url = '192.168.1.2/androidapi/public/insertuser';

This is my reference: IONIC, Access-Control-Allow-Origin

Community
  • 1
  • 1