开发者

Configure Firefox to allow Testing Cross Domain JSON Ajax calls from a file:// URL

开发者 https://www.devze.com 2023-02-19 20:04 出处:网络
Is it possible to set up Firefox to allow JSON/Ajax calls to my server from a client html page loaded using the file:// protocol??

Is it possible to set up Firefox to allow JSON/Ajax calls to my server from a client html page loaded using the file:// protocol??

I am building a phonegap application which is loading web pages using the file:// protocol and therefore XSS/XDS sandboxing rules don't apply. This is cool! Unfortunately, I can only get this to work from my Android Emulator (see below for setup). It does NOT work under Firefox running on my Vista client machine. This is disappointing because I have grown u开发者_StackOverflow中文版sed to using Firebug on the client to debug my application.

FYI, The following setup works fine (but doesn't allow Firefox/Firebug debugging)...

Server: Ubuntu running on Virtual Box, Eth0 in Bridged mode, node.js returning a JSON messages) Development (Host) Machine: Windows Vista running Eclipse with Android SDK and Phonegap stuff loaded Client: Application (.apk) deployed to the standard Android Emulator

Edit: I eventually gave up on this and used JSONP :/


I know you like Firefox but you could try Safari on Windows since it allows cross domain from file:// and it has good tools in the form of web inspector.

You could also try Sleight (https://github.com/alunny/sleight). which is a very simple proxy written in NodeJS specifically for PhoneGap.


It looks like pre-Firefox 3, you could configure Firefox to allow cross-domain requests but not anymore.

I have two suggestions that you could explore:

  1. If you have control over the server, you could set the Access-Control-Allow-Origin header in your response from the server (temporarily) to * to allow anyone to get data from your URL (remember to remove that later!).

  2. Use a proxy. It's pretty easy to set up Apache as proxy+reverse proxy for a limited number of URLs. This avoids the need to touch your server-side code and is probably the quicker, more reusable and less error prone of the two options.

    • http://www.apachetutor.org/admin/reverseproxies
    • http://httpd.apache.org/docs/2.0/mod/mod_proxy.html


Use Chrome. Its debug module is nearly Firebug in terms of quality and if you open it with

chrome.exe -allow-file-access-from-files

...it will allow cross-file access.

0

精彩评论

暂无评论...
验证码 换一张
取 消