Cordova (Phonegap) 2.0 In Android 4.1 Jelly Bean XMLHttpRequest Could not Load Error

Hello,

This is short and quick blog on cordova and android Jalley Bean issue. Have you ever encountered error “XMLHttpRequest Could not Load“ while working with Android 4.1 Jalley Bean? Complete error is XMLHttpRequest Could not Load, origin null is not supported.

First when I get this error, I thought it’s a cross domain issue, but it’s not. When you are using cordova all your JavaScripts are loaded by file:/// protocol. So it really does not matter if we use Ajax or JsonP request. Because there is nothing like domain here. So what really is the issue?

While debugging for this error I noticed in my chrome developer tools that, it’s trying to fire an XMLHttpRequest on my local machine and that XMLHttpRequest was initiated by some cordova functions. and that was using localhost url which does not exists. So it was breaking the whole app.

How to get rid of this? While debugging I found that this XMLHttpRequest was initiated by polling function of cordova. Cordova has polling mechanism to get response from native API calls. In my app, there wasn’t any native API call so I disabled the polling. Find the following line in your cordova file.

UsePolling:true,

and set it to false as follow.

UsePolling:false,

That’s it and there will not error on XMLHttpRequest.

Hope this helps you.

This entry was posted in Android, Cordova, Phonegap, Sencha Touch 2 on by .

About Hiren Dave

Hiren Dave is a software engineer, blogger and consultant with over 9 years of professional experience. He writes code in number of languages. Hiren has a passion for developing web apps, mobile apps and writing books and blog articles about programming. He has a solid experience of startups as he manages products for few startups. He is also passionate about researching and learning new technologies and trends. He has also authored a book Instant Sencha Touch, published by Packt and creator of Video Course "Beginning Laravel" for Packt

2 thoughts on “Cordova (Phonegap) 2.0 In Android 4.1 Jelly Bean XMLHttpRequest Could not Load Error”

  1. Rakhi Shah

    Nice post… I am facing the similar issue but unfortunately in my cordova.js file, usePolling is already set to false and still I get this error!!!

    Reply ↓

Leave a Reply

Your email address will not be published. Required fields are marked *