MacGapProject / MacGap1

Desktop WebKit wrapper for HTML/CSS/JS applications.
Other
3.55k stars 209 forks source link

HTTP Callouts #43

Open ghost opened 12 years ago

ghost commented 12 years ago

Does the Same Origin Policy apply for a MacGap webkit window? In other words can I send HTTP requests to multiple endpoints? Regardless, is there an API for making an HTTP callout without using a server proxy?

I The following JQuery function is failing for me:

$.ajax({ type:"GET", url: "https://www.google.com/", data: "", processData: false, success: function(r) { alert('success') }, failure: function(r) { alert('fail') }, complete: function(r) { $("#main").html(JSON.stringify(r)) } }); });

liamks commented 12 years ago

If you enable the developer tools the exact error type should be printed to console (hopefully).

ghost commented 12 years ago

Thanks for the tip. The exact error is indeed a same origin error:

5/17/12 1:09:27.602 PM MyApp: JavaScript console: :1: XMLHttpRequest cannot load https://www.google.com/. Origin http://localhost:3000 is not allowed by Access-Control-Allow-Origin.

So there are two possibilities. Either we can disable this somehow, or there is a way to expose the underlying HTTP callout method in the API. Suggestions?

ghost commented 12 years ago

Ok an update to this:

I was loading my entire index.html file from a server, which was causing the same origin issue. When I loaded the file directly from the app, then it worked fine! Not sure if this is intended behavior or not, but at least there is a way to make it work.

liamks commented 12 years ago

Good to hear you've come up with a solution. I think CORS can be enabled using the private API. We've enabled some methods in the private API:

https://github.com/maccman/macgap/blob/master/MacGap/Classes/ContentView.m (see lines ~21)