XMLHttpRequest - Cannot use wildcard in Access-Control-Allow-Origin

3,744 views
Skip to first unread message

sgehrman

unread,
Mar 22, 2012, 3:28:55 AM3/22/12
to General Dart Discussion
Just started with Dart and my first task was doing an XMLHttpRequest
get on an rss feed.

I get this error:

XMLHttpRequest cannot load http://webservices.nextbus.com/service/publicXMLFeed?command=routeList&a=sf-muni.
Cannot use wildcard in Access-Control-Allow-Origin when credentials
flag is true.

So I modified the XMLHttpRequest.getTEMPNAME code to set
withCredentials = false and that worked.

I know nothing about web programming, so could anyone explain the
problem in layman's terms and tell me how I can do this correctly? I
read something about launching Chromium with special flags? If that's
the case, how can I set up my build machine to "just work".

Thanks,

-steve

Bob Nystrom

unread,
Apr 5, 2012, 8:44:57 PM4/5/12
to sgehrman, General Dart Discussion
On Thu, Mar 22, 2012 at 12:28 AM, sgehrman <sgeh...@gmail.com> wrote:

I know nothing about web programming, so could anyone explain the
problem in layman's terms and tell me how I can do this correctly?  I
read something about launching Chromium with special flags?  If that's
the case, how can I set up my build machine to "just work".

Sorry, this email kind of fell through the cracks, probably because none of us are experts when it comes to this. We're good at answering Dart questions, and questions about the libraries we provide. We aren't as good at some of the dark corners of web programming.

- bob

fils

unread,
Apr 16, 2012, 12:38:04 PM4/16/12
to General Dart Discussion
I am running into this same "Cannot use wildcard in Access-Control-
Allow-Origin when credentials flag is true" issue

I also modded the code and even set the CORS value on my RDF triple
store (virtuoso) to allow the URL I am coming from. I now get a

"Credentials flag is true, but Access-Control-Allow-Credentials is not
"true"." reply

Is there any example of using XMLHttpRequest.getTEMPNAME to call to a
cross origin resource that works? (that doesn't involve modding the
SDK source)

Is there a better library or approach to do this with? I've been able
to resolve this in the past in JS so I assume there is a path to this
working. I just see it. :) (no surprise)

On Apr 5, 7:44 pm, Bob Nystrom <rnyst...@google.com> wrote:

Seth Ladd

unread,
Apr 16, 2012, 1:14:00 PM4/16/12
to fils, General Dart Discussion
Hi Fils,

getTEMPNAME is meant for ultra-simple use cases. You can always drop down to standard XHR API and set the headers that you require. A good resource for XHR is MDN: https://developer.mozilla.org/en/DOM/XMLHttpRequest/Using_XMLHttpRequest  (skip to asynchronous)

Let us know if the raw XHR API isn't doing what you need.

Thanks,
Seth

Douglas Fils

unread,
Apr 16, 2012, 2:01:36 PM4/16/12
to Seth Ladd, General Dart Discussion
Seth,
  Thanks much..   that got it in one!  

  And I found..  https://github.com/chrisbu/dartwatch-JsonObject  which is simply too nice!

now I can do..  

String k = encodeComponent("""
Select  ?s ?p 
WHERE {
  ?s ?p "Trochospiral"
}
""");

 request = new XMLHttpRequest();  


  request.send(null);  
  
  print(request.responseText);  //  just nice to see it..  
  var sr = new JsonObject.fromJsonString(request.responseText);
  print(sr.results.bindings[0].p.value);  //  is it this simple?
  
  for (JsonObject x in sr.results.bindings) {
    print(x.s.value);  //  gives a warning "x is not a member of JsonObject" yet seems to work?  Need to resolve
  }

I'm really starting to like Dart.  :)   It just feels so much more like the languages I normally use.  

Seth Ladd

unread,
Apr 16, 2012, 2:05:50 PM4/16/12
to Douglas Fils, General Dart Discussion
Great to hear! Keep us posted on your progress. BTW do you have this code open sourced somewhere?

Chris Buckett

unread,
Apr 16, 2012, 4:30:59 PM4/16/12
to Douglas Fils, General Dart Discussion
Hi Douglas


  for (JsonObject x in sr.results.bindings) {
    print(x.s.value);  //  gives a warning "x is not a member of JsonObject" yet seems to work?  Need to resolve
  }

You get the warning because JsonObject is using the "noSuchMethod" function - it tries to load the getter for x (or whatever), can't find it, and noSuchMethod then tries to look it up in parsed json map.  As the x getter doesn't actually exist, the tools log this as a warning.


Gilad's reply on this thread indicates that fixing this is on the radar:
"The overall question of how to tell the type checker to just shut up about 
a specific issue remains open. I think we should do something on that front 
as well, but we're not there yet. " - Gilad.


Cheers,
Chris.




Reply all
Reply to author
Forward
0 new messages