-1

I'm trying to build a HTML5 mobile app using Intel XDK. For some reason, when I emulate on the Intel XDK it works but when I try it on a real device I get the error alert

http://localhost The following error occured: {"readyState":0,"responseText":"","status":0,"statusText":"error"}

request = $.ajax({
                    url: "http://domain.com/form.php",
                    type: "post",
                    data: serializedData
                });

                // callback handler that will be called on success
                request.done(function (response, textStatus, jqXHR){
//do stuff
                });

                // callback handler that will be called on failure
                request.fail(function (jqXHR, textStatus, errorThrown){
                    // log the error to the console
                    alert(
                        "The following error occured: "+
                        JSON.stringify(jqXHR,textStatus,errorThrown)
                    );
                });
hexicle
  • 2,121
  • 2
  • 24
  • 31
  • I think there is a server side error. Can you share some server side code? Can you debug it yourself? – Patrick Hofman Mar 26 '14 at 11:17
  • the server side PHP code is fine because I have a desktop website which works completely fine off the server side PHP code. The problem is that I'm trying to make a mobile app and the request fails in the mobile app. The request succeeds in the desktop website. However, the desktop websites runs on the server itself, so perhaps this is a cross-site scripting problem? But I thought this isn't cross-site scripting because it's running off a mobile app, not a separate server. – hexicle Mar 26 '14 at 11:19
  • So, what are you posting? Does it influence handling on the server? Can there be a bug there? – Patrick Hofman Mar 26 '14 at 11:19
  • are you posting to the same domain? – stackunderflow Mar 26 '14 at 11:20
  • I checked the serializedData that I'm posting to the server and it's fine. I'm posting from a HTML5 mobile app to the domain. – hexicle Mar 26 '14 at 11:21
  • What puzzles me is that in the alert, the 'title' of the alert is http://localhost, despite the fact that I'm not trying to use localhost from the HTML5 mobile app since that wouldn't make sense. The server side code starts off with ` – hexicle Mar 26 '14 at 11:25
  • I think that this is a same origin policy problem. I think that my mobile app 'thinks' that it's the server `http://localhost`, so it doesn't want to connect to the foreign server `http://domain.com` and thus I should solve the problem using solutions like jsonp. – hexicle Mar 26 '14 at 11:32
  • My question is a duplicate of http://stackoverflow.com/questions/10555285 and http://stackoverflow.com/questions/19395354 – hexicle Mar 26 '14 at 11:34

1 Answers1

0

It is probably failing because of cross-origin request, you have to add these script tags to work around the cross-origin error in Intel XDK apps:

<script src="intelxdk.js"></script>
<script src="xhr.js"></script>

actual script files are not required, you just need to add the above script tags to index.html it will be automatically included in Intel XDK builds. Here is more details.

krisrak
  • 12,882
  • 3
  • 32
  • 46
  • It seems that include xhr.js affect local file loading. I'm having a lot of trouble with xhr. If I include it I can do server call but I cannot se css and load links, viceversa if I don't include it... someone are experiencing the same problem? – ivy Jul 29 '14 at 07:06
  • I forget to mention that I'm using angular routeProvider and $location.url("/login"); to load files – ivy Jul 29 '14 at 07:37