2

I am new for cross platform mobile app development using HTML frameworks like Sencha. Today, I've downloaded Sencha Touch 2.3.1 and tried to open an index file in the examples folder came with the download package.

Surprisingly I couldn't see anything and my console log said

Cross-origin-requests-are-only-supported-in-HTTP

for bootstrap.json

I have seen the same error for some html files on lungo framework's examples. What could be the reason for this ?

I hope all these files will load correctly if I upload them on a server, but I will be wrapping the js file as package while building the app, so this will not work.

I am aware of the Cross Origin Policy which restricts JS to send request to different origin, but I don't understand why this is happening when I have these files locally. Please help me understand this and explain how to overcome this issue.

Bala
  • 3,576
  • 10
  • 46
  • 74
  • are you accessing your site from a local webserver? i.e. `localhost/` – actual_kangaroo Dec 21 '13 at 12:16
  • no, I am accessing local file system i.e file:// and this have no PHP or server side scripts involved. It is just an example comes with Sencha Touch 2 bundle – Bala Dec 21 '13 at 12:20
  • 1
    that is your problem! most browsers will disallow requests to files that are called from javascript, I'd recommend wamp http://www.wampserver.com/en/ – actual_kangaroo Dec 21 '13 at 12:25

1 Answers1

3

when you open the page with file:// protocol, the browser disables requests to other files. so when schena touch tries to load bootstrap.json, your browser throws that error. the solution is to host your site on a local webserver and access it through http://localhost/

I recommend appache server, wamp if you're on windows

Another answer explains

Community
  • 1
  • 1
actual_kangaroo
  • 5,971
  • 2
  • 31
  • 45
  • 1
    But some other files are working only specific files are not working. Anyway how can I overcome this issue when I build the app after development, files have to be called locally when installed on a mobile phone as an application – Bala Dec 21 '13 at 12:35
  • It appears that once you build the app, it will use `http` even if the file is hosted locally, so this won't be a problem http://www.sencha.com/forum/showthread.php?198987-Touch-2.0.1-Build-app-issue – actual_kangaroo Dec 21 '13 at 12:44