Software Archive
Read-only legacy content
17060 Discussions

Works in Emulator but not App Preview

phil_J_
New Contributor I
945 Views

I'm creating an App that needs to send data up to a server and then retrieves data. Just getting the functions to work before I start to format and 'pretty it up'.

The POST functions fine and I capture with a php server that put into the database.

Using Ajax GET to retrieve the data, again from a php sender, and it works fine in the Emulator - but on App Preview it just crashes. Could anyone help please?

The JS function that is doing the GET and just displaying some of the data is as follows; (off the click of a button called 'butget'.

 

Like I say in the Emulator it displays the result, but on App Preview it just crashes the App Preview App.

<script type="text/javascript">
      
            $(document).ready(function() {
            $("#butget").click(function(){  
            var xhr = new XMLHttpRequest();
            xhr.open("GET", "http://myurl.testget.php?names=json", false);
            xhr.onload = function(){
                          
            var gotdata;
             if(xhr.status == 200)
             {     
                 gotdata = JSON.parse(xhr.responseText);                        
                 intel.xdk.notification.alert(gotdata.Name1, "Name 1");                
             }
             else if(xhr.status == 404)
             {
                 intel.xdk.notification.alert("Web Service Doesn't Exist", "Error");
             }
             else
             {
                 intel.xdk.notification.alert("Unknown error occured while connecting to server", "Error");
             }
            }
            xhr.send();
           
             });
            });
           </script>
       

 

 

 

0 Kudos
10 Replies
PaulF_IntelCorp
Employee
945 Views

Does it also fail if you use the Debug tab? The Debug tab runs on device but gives you a better debugging environment. It can be used with an Android or iOS device. Please give it a try.

0 Kudos
phil_J_
New Contributor I
945 Views

Been testing on iOs but don't have a dev account with Apple yet, so borrowed wife's Samsung - and it works OK thru that using App Preview?

 

 

0 Kudos
phil_J_
New Contributor I
945 Views

Got the debugging working on Android - but the code works...not sure what to look at.

It ALSO works fine on my Kindle (Android also)....

0 Kudos
PaulF_IntelCorp
Employee
945 Views

If this is an iOS-specific problem then you're either going to have to get yourself an Apple dev account so you can do USB-connected debugging, or use the Test tab with the weinre script, for very limited debugging (you can, at minimum, perform the AJAX call from the console using weinre and see what happens). See these doc pages for hints on how to use weinre:

0 Kudos
phil_J_
New Contributor I
945 Views

ok thanks, will get an account.

Are there ant more reliable ways to do what I want...any sample code?

0 Kudos
PaulF_IntelCorp
Employee
945 Views

Use real AJAX calls, not the old intel.xdk APIs, those have been deprecated and will be going away.

0 Kudos
phil_J_
New Contributor I
945 Views

Ok Thanks - can you point me to any tutorials or sample code? I am quite new to this....

 

 

0 Kudos
PaulF_IntelCorp
Employee
945 Views

For standard HTML5 good places to look for info are the HTML5 Rocks site and W3 Schools site. Search for AJAX.
 

0 Kudos
Pamela_H_Intel
Moderator
945 Views

FYI - Just in case you weren't aware - there is no longer cost for Apple dev licenses (for testing only). That was announced at WWDC in June.

Correction:

Apple no longer requires a developer's license if you are only testing - that was announced at WWDC in June, though I haven't gone through the process myself. Supposedly you only need to sign in with your AppleID.

 

Here is the page that discusses Apple's free provisioning: Read under the heading "Launch Your App on Devices Using Free Provisioning"https://developer.apple.com/library/prerelease/ios/documentation/IDEs/Co...

Note: some capabilities are not available (but as far as I can see they are related to sales type functionality - so you would not be able to test things like In-App purchases).

0 Kudos
phil_J_
New Contributor I
945 Views

Thanks Pamela.... Will look into that

0 Kudos
Reply