phonegap-app-developer: ajax calls fail with Phonegap serve

I also have a problem with ajax calls. The request’s status is simply “Pending” as viewed by the “Network” tab of Weinre. The code I am using is also very simple.

$$.ajax({ method: 'GET', url: domainURL  ,processData: true, data:dataToSend,dataType: "json",
           success: function (data) {
            alert(data);
           }, error: function (data){
            alert("error") ;
            alert(data);
         }  });

I am using Phonegap serve to run the app containing the above code. The implementation of ajax I used is that of Jquery and also Framework7. Their ajax calls work perfectly fine in the desktop pc browser, in my mobile devices browsers (including Safari and Chrome), but NOT when built with Phonegap serve. I am testing on iPhone and iPad.

I am using version 3.5.0-0.20.4 of phonegap

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Comments: 36

Most upvoted comments

Not sure why this is closed. There has been no resolution and it is still a problem.

When using the default hello world template that is created in phonegap desktop, you cannot create a cors request. It has the whitelist included and allows *, so there should be no restrictions.

It serves from a local URL of 10.50.3.64:3000.

When I execute a basic get with the following vanilla JS: var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (xhttp.readyState == 4 && xhttp.status == 200) { console.warn('DONE'); } else if (xhttp.readyState == 4 && xhttp.status !== 200) { console.error('DEAD'); } }; xhttp.open("GET", "https://aligntoday.com", true); xhttp.send();

It errors with a 404 not found because it changes the request URL to : http://10.50.3.64:3000/proxy/https%3A%2F%2Faligntoday.com

Any ideas how to make it stop altering my URL?

some helpfull info http://stackoverflow.com/questions/39097721/how-fix-or-disable-proxy-in-phonegap I’ve thought i need to disable proxy but in my case I just needed to supply full URL for my API. I’ve created Settings var in www/js/index.js and supplied my scripts full URL like http://myhost.local also temproarily disabled CSP by commenting out metatag in www/index.html <!-- <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;"> --> Hope it’ll help someone.

I have the same problem: I wrote a script that works fine when accessed from a normal web server, but that once called in the Phonegap environment tries to access a mangled version of the one submitted(http://materiali.c-s-m.it/phonegap/), as I could see from the Chrome debug: http://undefined/proxy/http://materiali.c-s-m.ithttp://materiali.c-s-m.it/phonegap/ Failed to load resource: net::ERR_NAME_NOT_RESOLVED

How is this issue closed with no resolution… my ajax calls aren’t working suddenly. I am using a POST request to send data to a C# service. Works perfectly in the web browser but not in ios with 8.2 sdk… please help. 7.1 works fine but not the current sdk.

I was running into this issue today and suspected that the proxy was failing because my AJAX url was using SSL. I converted to non-SSL to confirm, and that did indeed fix it. If SSL support is intended, this ticket should be re-opened.

image

image