Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Novice
9 Views

Ajax request problem

Hello,

Im a newbie and I have some problems with my app. When I click the button to make cross domain ajax request to the server side (not localhost) it works fine in the emulator, but it doesn't work on my phone in the intel app preview. I read other topics with the same problem and I haven't yet found a solution to this problem. Also there is not enough information about it in the internet and i can't find ANY full and correct tutorial relative to server side requests step by step. Somebody has solved similar problem with older versions of Cordova CLI but nobody writes how he did it. I installed intel xdk a few days ago and I really like it! It is easy to work with, but now I can't find out what is wrong with ajax requests. So, without communication with the outside world my app is usless and soon Im going to start design it with phonegap, because everybody writes that there is no same problem with it.

I use 5.4.1 Cordova CLI version. I configured whitelist in build settings like so (*, http:\\*, https:\\*) and checked Cordova Android Whitelist (not Cordova Legacy) and it doesn't make sense if I write anything in the whitelist. It works in the emulator, but in the app preview it doesn't.

Can anyone help me and describe step by step how to configure it correctly from start to the end? I just want to test a supersimple ajax request to my server and receive some data in the app preview to enshure that it will work after publishing.

Thanks for answers and sorry for grammar :)

Tags (2)
0 Kudos
15 Replies
Highlighted
Novice
9 Views

No one can help me? Srsly?

I have tried the same code with phonegap build and it works fine on my android device without any additional app preview software! Now I can make ajax requests and update information in my mobile app and it is great!

It seems that intel xdk is little bit buggy. I tried a lot of things to make it work but to no avail. I did not expect that there will be such a problem with such basic things... Goodbye, intel xdk!

0 Kudos
Highlighted
Valued Contributor I
9 Views

Hi,

I think that you don't give you enough time to test XDK. I'm using it from about a year and can solve any trouble I found with the help of this forum and searching the web.

There are some aspects of the apps than work different when you are in Emulator, Debug, App Preview and builded apps. Unfortunately, you will need to dedicate some time to learn how these options work.

About your problem, I can't say without more info, what kind of service are you calling by ajax?

You say that phonegap build works. Did you try to build your app with XDK instead of using App Preview? I suspect that it will work too.

Have some patience, you are asking something during a weekend. Intel's staff check the forum and reply usually very quickly on Monday – Friday, 09:00 – 17:00 Pacific Time (GMT –7:00).

Best wishes,

Diego

0 Kudos
Highlighted
Novice
9 Views

what kind of service are you calling by ajax?

Does it really matter what kind of service Im trying to call by ajax? As I wrote above that I send a super simple ajax request and put received data to a div in my html page. It works fine in my browser on PC and in the emulator, but not in app preview.

I can't say without more info

What information do you want to know exactly? I can post my code here.

This is my ajax request

var url = 'https://control-borisko.c9.io/ajax-test/echo.php';
$.ajax ({
    url: url,
    type: "GET",
    dataType: "text",

    success: function(data){ $('.ajax-result').html("Request succeeded. Data: " + data); }, 
    error: function(xhr) { $('.ajax-result').html("Request error"); }
});

This is my server side code written in PHP (I use free vds, and it works only when I run it manually)

<?php
   header('Content-type: text/html');
   header('Access-Control-Allow-Origin: *');
   echo 'Hello!';
?>

Also I configured whitelist

screen-1_0.jpgThis is how it works

screen-2.jpg screen-3_0.jpg screen-4_0.jpg

Did you try to build your app with XDK instead of using App Preview?

No, I didn't. I haven't got any certificates yet and it is quite difficult for me to understand the workflow at first time. I found out that the easiest way to test my app is to install app preview on my mobile device.

So, what I want to say that there is no detailed tutorial about this stuff and information base is very poor and that is why Im here.

Then I tried to build the same project with phonegap build (it does not require a certificate for android) and I installed my apk file on my mobile device and it works fine! I spent a few hours to figure out how to do it with phonegap build and it was quite easy because there is detailed info about how to do it! In case of intel xdk I spent more than one day and do not have a result yet. It is disappointing.

I'm using it from about a year and can solve any trouble

So, why don't you answer my question and give some working example with some details?

Thank you.

0 Kudos
Highlighted
9 Views

Boris -- there have been issues with jQuery 1.x and AJAX calls, in the latest versions of Cordova. For most people, simply changing to jQuery 2.x solves the problem. We have multiple posts regarding this issue in the forum.

0 Kudos
Highlighted
Novice
9 Views

Thank you very much! I downloaded jquery-2.2.3. It is working now. It is very strange that I havn't found any info about it earlier.

0 Kudos
Highlighted
Beginner
9 Views

Thanks for this Paul.

You saved me from pulling my hair out!! :) 

0 Kudos
Highlighted
Beginner
9 Views

i checked my version of jquery and i have installed jQuery v2.1.4. I add my list of domains to the white list however my ajax call seems not to be triggered. it works perfectly on my desktop browser, within the simulator however during app preview it does not fire. 

  $.ajax({url: 'https://www.myserver.com/api/login.php',
                              data: {action : 'login', formData : $('#login_user').serialize()},
                            type: 'POST',       
                            async: 'true',
                            dataType: 'json',
                            beforeSend: function() {
                                var opts={
                                    message:"Please wait.......",
                                    position:"tc",
                                    delay:2000,
                                    autoClose:true,
                                    type:"error"
                                };
                                $.afui.toast(opts);
                            },

0 Kudos
Highlighted
Valued Contributor I
9 Views

Xavier> did you try with jquery-2.2.3?

Insert 1 line in the code, before $.ajax, with "console.log('something');" and look the console. Confirm that the program pass by this point. Maybe an error, before the ajax call, is broking the program.

0 Kudos
Highlighted
Beginner
9 Views

i also tried the following upgraded my jquery file to version 3.1  and added the following scripts within the project

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

i have also added the the domain within the network access as follows http://myserver.com/*

and still to no success. As stated before the code works fine within the simulator, desktop browser unfortunately not within app preview

0 Kudos
Highlighted
Valued Contributor I
9 Views

Are you debugging in order to see any error message?

Try insert these lines in your JS file:

//ativar em caso de necessidade de entender algum erro
window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {
    alert('Error: ' + errorMsg + ' Script: ' + url + ' Line: ' + lineNumber + ' Column: ' + column + ' StackTrace: ' +  errorObj);
 };

 

0 Kudos
Highlighted
Beginner
9 Views

this is what i did

$(document).ready(function(){

    window.onerror = function (errorMsg, url, lineNumber, column, errorObj) {

    alert('Error: ' + errorMsg + ' Script: ' + url + ' Line: ' + lineNumber + ' Column: ' + column + ' StackTrace: ' +  errorObj);

 };
        
        });

Thanks for the tip i implemented the call within my as suggested below and i got the following error

Error:Uncaught TypeError: undefined is not a functionnscript: file://android_asset/overrideXMLHttpRequest.js Line:16

Column: 69 StackTrace: TypeError: undefined is not a function

i am not sure  what this mean given that its only within the app preview this error is thrown

 

 

0 Kudos
Highlighted
Beginner
9 Views

will try the jquery-2.2.3.min.js and let you know

0 Kudos
Highlighted
9 Views

0 Kudos
Highlighted
Beginner
9 Views

I cannot express how greatfull i am to you Paul F. (Intel) . i have been researching the error for over a week and almost came to the conclusion to explore another IDE. i cannot believe the issue is something that could be solved that simple. just adding the <head data-noxhrfix> tag to my header allowed me to see the results of my ajax immediately. WoW.. Many thanks to you and your team however you do need to document this issues so other persons can reference it.

0 Kudos
Highlighted
9 Views

Thank you very much Paul F. (Intel), you helped me a lot. 

Muchas gracias Xavier P., vaya chorrada !!!

0 Kudos