2

I have a cordova app and it worked fine until this morning. I think it has something to do with the new update to cordova 6.4.0.
Whenever I'm sending an AJAX request to my API and it stay in pending more for ever. I've waiting 15 minutes and they still havn't come back. I have the whitelist plugins updated, i added the correct info in the config.xml :

<plugin name="cordova-plugin-whitelist" spec="1" />
<allow-navigation href="*" />
<access origin="*" />

And there are the version of my cordova and plugins

cordova-plugin-compat 1.1.0 "Compat"
cordova-plugin-file 4.3.0 "File"
cordova-plugin-network-information 1.3.0 "Network Information"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-plugin-x-toast 2.5.2 "Toast"
phonegap-plugin-push 1.8.0 "PushPlugin"

Do you have any ideas on how to fix this Thanks

edit

Here is the code I am using to make Ajax request. I'm returning the Ajax element so I can attach a .done() or a .fail() function to it.

this.get = function($url, $data, $beforeSend) {
    /*if($url.indexOf('http') == -1) {
        $url = this.URL_API + $url;
    }*/
    $url = this.URL_API + $url;
    if(typeof $data !== 'object') {
        this.error('Erreurs de type de donnée.');
    } else {
        console.log($url);
        return $.ajax({
            url: $url,
            method: 'GET',
            data: $data,
            beforeSend: function(xhr) {
                if(typeof utils.userdata !== "undefined") {
                    xhr.setRequestHeader('X-API-KEY', utils.userdata.key);
                }
                xhr.setRequestHeader('Content-Type', 'application/json');
                console.log(utils.userdata);
                console.log($data);
                if($beforeSend !== null && typeof $beforeSend == "function"){
                    $beforeSend();
                }
            }
        });
    }
}

I'm also adding an X-API-KEY header to my request but that shouldn't be the problem.

Nicolas
  • 8,077
  • 4
  • 21
  • 51
  • Have you tried getting failure function in ajax call ? Are you getting any error response from api ? Please share your ajax code too. – Kirankumar Dafda Dec 21 '16 at 05:34
  • @KirankumarDafda I did, and the request is still in pending so it never reaches the failiure callback – Nicolas Dec 21 '16 at 16:43
  • One of my got the same issue but it was because of his wifi, and then it was working perfect with mobile net. so are you sure that there is no other reasons that not going to send ajax request ? because there is no change required into plugins and config file. – Kirankumar Dafda Dec 22 '16 at 05:18
  • I know that's why I have absolutely no clue. I have tested it on a few devices, in a few places and still the same result. – Nicolas Dec 22 '16 at 05:19
  • Can you share your ajax request code too, so I can check or suggest any other idea to resolve this – Kirankumar Dafda Dec 22 '16 at 05:21
  • @KirankumarDafda I edited my question with some code if that can help – Nicolas Dec 22 '16 at 05:33
  • +1 upvote to your question for finding the issue with upgdrading cordova version, because our most of application uses ajax request to communicate with live data. – Kirankumar Dafda Dec 22 '16 at 06:15

1 Answers1

1

As you said that it was working fine before updating it to new version of cordova

Then you can downgrade it with the below command and check if everything working fine again or not.

$ sudo npm install -g cordova@6.2.0

And if the problem remain same then there is the problem either from your ajax call or you need to check your API via postman and check if it is working fine or not.

Kirankumar Dafda
  • 2,354
  • 5
  • 29
  • 56
  • I haven't tried downgrading Cordova, I will try it now. I do know though that my API is correct since it's working in postman and in my web app. In this case, Cordova is the problem. – Nicolas Dec 22 '16 at 05:32
  • Yes, then you have to try atleast once downgrade the cordova version, since I was thinking of update to cordova new version but not now. – Kirankumar Dafda Dec 22 '16 at 05:35
  • 1
    I'm upvoting your answer because downgrading Cordova fixed the problem. It did not fix the problem if I had still wanted to use Cordova 6.4 so I want to keep the question open. But still, good job ! – Nicolas Dec 22 '16 at 06:09
  • It's helpful for me too, to check that updates of cordova will cause any problem or not. Thanks :) – Kirankumar Dafda Dec 22 '16 at 06:17