Loading...

prototype-scriptaculous@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

[Proto-Scripty] Re: Ajax.Request fails, while vanilla XHR works fine Victor Thu Apr 12 10:00:15 2012

>
> Same browser (Safari.latest) on the same computer, the Prototype method 
> gives me a security failure (Origin [my host] is not allowed by 
> Access-Control-Allow-Origin.) while the long-hand XHR (inside a Prototype 
> observer) just works without any comment:
>
>
> Two differences I can notice:
1. Prototype sets request headers 'X-Requested-With', 
'X-Prototype-Version', 'Accept' with setRequestHeaders() - you don't
2. Prototype calls send with null argument
    this.transport.send(null); // Prototype
vs
    client.send(); // your raw XHR

If you can test your code with these two changes - will it raise error?

  $('zip').observe('change', function(evt) {
    var client = new XMLHttpRequest();
    client.open("GET", 
"http://zip.elevenbasetwo.com?zip=<http://zip.elevenbasetwo.com/?zip=>" 
+ $F(this), true);
    client.onreadystatechange = function() {
      if(client.readyState == 4) {
        var data = client.responseText.evalJSON();
        $('city').setValue(data.city);
        $('state').setValue(data.state);
      };
    };
*    client.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
    client.setRequestHeader('X-Prototype-Version', '1.7');
*
*    client.setRequestHeader('Accept', 'text/javascript, text/html, 
application/xml, text/xml, */*');*
    client.send(*null*);
  });

-- 
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/prototype-scriptaculous/-/6dUgLVmeJQkJ.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en.