Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
652 views
in Technique[技术] by (71.8m points)

cordova - Visual Studio, Ripple Emulator and CORS/Cross Domain Ajax

I have an issue with Visual Studio when working on a multi device hybrid app. When I try do to an ajax call to an external webservice, and get some errors in ripple. (Cross Domain Security issues). My code works fine when deploying to a mobile device.

From research I found the following:

  • Ripple has its own proxy settings

    • In Ripple, go to settings, and choose local, disabled, or remote (depending on your situation) on the proxy setting.
    • This seemed to work for some people, but I now have a different error. (Bad Request)
  • I found more info that Chrome can be started in no web security mode, by means of a command line switch when you run it.

    • The issue with this, is that Visual Studio seems to have hard coded the path to Chrome, that it uses to open ripple.
    • I therefore cant start chrome in no web security mode...
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I had exactly the same problem as Louis, but since Chrome 48 all the CORS extensions seem to have stopped working. I've come up with an alternative solution which I thought I'd share.

  1. In your Chrome installation directory - probably C:Program Files (x86)GoogleChromeApplication - create a shortcut to the chrome.exe
  2. Right click on this shortcut and select Properties
  3. On the Shortcut tab, in the Target field append the following two fields --allow-file-access-from-files --disable-web-security 4 . Save this and rename the shortcut to "Google Chrome - Debug with Ripple"
  4. Right click on it and select Pin to Start Menu

This shortcut will allow you to run Chrome with no web security, which allows CORS in Ripple. By using a shortcut this will not interfere with your normal use of Chrome. Now in order to use Ripple

  1. In Visual Studio debug your app which will start Ripple in its own Chrome instance
  2. Now open the start menu and click on the pinned "Google Chrome - Debug with Ripple" shortcut
  3. A second instance of Chrome will launch with a warning of "You are using an unsupported command-line flag: -- disable-web-security. Stability and security will suffer."
  4. Copy the Ripple proxy URL from the Visual Studio instance to this new one, for example http://localhost:4400/index.html?enableripple=cordova-3.0.0-NexusS
  5. Your CORS requests will now work in Ripple.

Note that Visual Studio has just been used to launch Ripple. Debugging will need to take place using Chrome's Developer Tools.

Note also that you can double check that Chrome is using your shortcut flags by browsing to the url chrome://version/

Hope this helps!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...