Software Archive
Read-only legacy content
17061 Diskussionen

Ajax calls are not works

Raiden_D_
Einsteiger
2.599Aufrufe

Hi!

My ajax calls are not works in the new xdk version!

My code:

jQuery.ajax({
                type:'GET',
           url:'http://time.jsontest.com/',
              error: function(response, d, a){
                alert(response + d + a) ;   
            },
            success: function (response){
                    alert(JSON.stringify(response));         
         }
            });

 

Response in xdk emulator on windows 7:

{"time":"12:31:52 PM","milliseconds_since_epoch":1425040312408,"date":"02-27-2015"}

Response on phone, after building cordova hybrid android app and install it (xiaomi redmi note and samsung galaxy note 3)

[object Object]errorNot Found

Why not works it? Help please! Thanks!

0 Kudos
18 Antworten
Cristian_C_
Einsteiger
2.599Aufrufe

Hi Raiden,

if you're using the latest version of Intel XDK (1816) that's the issue. We had the very same problem. When we update from 1621 ajax calls stopped working, together with simpler things like anchor tags (!!!). We had to revert back to version 1621. Please, refer to this topic in order to rollback.

Swati_S_Intel1
Mitarbeiter
2.599Aufrufe

Have you included intelxdk.js and xhr.js in your index.html?

Have you been able to run it on your device using App Preview?

 

Swati

Swati_S_Intel1
Mitarbeiter
2.599Aufrufe

@Cristian, the build system is independent of the XDK UI. The new version should not affect the functioning of built app.

Swati

Vijay_R_1
Einsteiger
2.599Aufrufe

Ajax calls work good for me in 1816 version.

     $.ajax({

           type: "GET",
            url: url + "/test",
            dataType: 'json',
            success: function(data){
                if (data[0].err) {
                    $("#data").append(data[0].err);
                  }
                    else {
                $("#data").html(data[0].status);
                    }
                  }
   });

 

Hamilton_Tenório_da_
Geschätzter Beitragender I
2.599Aufrufe

In the past I had this issue. I discovered that I had appframework AND jquery files. It caused the problem. I removed the appframework file and all worked well.

Vijay_R_1
Einsteiger
2.599Aufrufe

Yes, i have also only included the appframework js scripts.

Hamilton_Tenório_da_
Geschätzter Beitragender I
2.599Aufrufe

Remove it and test again!

Raiden_D_
Einsteiger
2.599Aufrufe

SWATI S.: I have included both js file in the index.html, and ajax calls are running in AppPreview.
It runs everywhere, except on phone (after building cordova android app)

Sreedev_M_1
Einsteiger
2.599Aufrufe

I understand that this is because of AppFrameWork, i removed it and using jquery mobile works with ajax calls.  Earlier (before upgrading XDK) this was working perfectly fine with AppFrameWork 2.2., If you guys have a solution to it with AppFrameWork, please post here. thanks

RafaOr
Einsteiger
2.599Aufrufe

Hi.

You must read this link for ajax call crossdomain: http://www.funcion13.com/2012/04/12/como-realizar-peticiones-ajax-cross-domain-jsonp-jquery/

En the php file you must include this instruction, header('Access-Control-Allow-Origin: *'); this is important to access to the file an get the json objet.

RafaOr
Einsteiger
2.599Aufrufe

Important that do not include additional domains in the section Domain list, just use the one that comes by default * and if you can update your Intel XDK to version 1816

Swati_S_Intel1
Mitarbeiter
2.599Aufrufe

I'm hearing different things for this ajax issue. Please load this attached project which makes ajax call using jQuery. I'm successfully able to build for Cordova Android and it runs on device as well. If it does not run for you, please send your device info - which device are you using, which android OS version- and what errors you get while you run this app.

Hope this helps.

Swati

Raiden_D_
Einsteiger
2.599Aufrufe

Your projects's ajax call works on my phone, but my own doesn't.
I did the following:
Start a new project --> Templates --> Blank --> HTML 5 + Cordova
I copied your ajax script, button, intelxdk.js, xhr.js and jquery file.
Next: Build --> Cordova Hybrid --> Android.
I installed the apk file on my mobile. The ajax works fine in the emulator, but not on my mobile.
It throws an error: [Object]errorNot Found.

My phones: Xiaomi redmi note and Samsung note 3. Android version on both device: 4.4

Why doesn't it work?

Thank you!

 

Sreedev_M_1
Einsteiger
2.599Aufrufe

Hi Raiden,

Did you solve this issue ? the Not Found error ?

Thanks

Leandro_M_1
Einsteiger
2.599Aufrufe

Hi Raiden,

Did you find any solution to the problem ?

I'm having the same problem when I do the Ajax call appears Error: Not found

Thanks
Swati_S_Intel1
Mitarbeiter
2.599Aufrufe

Hello,

There is an issue, when you create a project from a template, the Domain List is left empty in the Projects> Build Settings and that's why the app cannot access other domain through ajax calls. I've reported the bug. Meanwhile please go to Projects Page and under Build Settings, put a * in the Domain List box. You'll have to do this for all the builds that you are using.

Thanks,

Swati

Marco_S_
Einsteiger
2.599Aufrufe

Hi SWATI,

I tried :

function TestAjax()
{
    $.ajax({
        type:'GET',
        url:'http://time.jsontest.com/',
        error: function(response, d, a){
            alert(response + d + a) ;  
        },
        success: function (response){
            alert(JSON.stringify(response));        
        }
    });
}

and it runs adding * into Build settings->Domain List .

unfortunately, my function below doesn't run:

function CheckMobile()
 {
    var url = 'https://assistenza.octaviangaming.com/renting/api/?mobile_num=' +            
                      document.getElementById("txtNumCell").value;
   
    $.ajax({
        url: url,
        type: 'GET',
        success: function(data, textStatus, jqxhr){
            CheckMobileEnabling_success(data, textStatus, jqxhr)},
        error: CheckMobileEnabling_err});      
 }

Swati_S_Intel1
Mitarbeiter
2.599Aufrufe

@Marco, what error do you get? Which android version are you testing this on?

Antworten