On Apr 12, 2012, at 12:14 PM, Victor wrote:
> 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=" + $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);
> });
>
>
Thanks very much for the suggestion. It looks as though ANY setRequestHeader
invocation at all is enough to scuttle the request. I tried commenting one,
then two, then all of them out. Without those three lines, the request works
fine -- even with the null in the send. But add any one of them back, and the
request fails. It seems to be an issue on their server (BaseHTTP/0.3
Python/2.7.1+ according to FireBug). I'll file a bug and see what happens.
Walter
--
You received this message because you are subscribed to the Google Groups
"Prototype & script.aculo.us" group.
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.