Prototype:
$('zip').observe('change',function(evt){
var elm = this;
new Ajax.Request('http://zip.elevenbasetwo.com', {
method: 'get',
parameters: {zip: $F(elm)},
onComplete: function(transport){
var data = responseText.evalJSON();
$('city').setValue(data.city);
$('state').setValue(data.state);
}
});
});
XHR:
$('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.send();
});
I don't trust this to work in the range of browsers supported by Prototype, naturally, so I'd really like to know what I could do to get it to work in Prototype.
Thanks,
Walter
On Apr 10, 2012, at 10:50 PM, Walter Lee Davis wrote:
> var data = responseText.evalJSON();
s/b var data = transport.responseText.evalJSON();
Walter
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 prototype-s...@googlegroups.com.
> To unsubscribe from this group, send email to prototype-scripta...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en.
>
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:
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
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
On Apr 13, 2012, at 5:26 AM, Victor wrote:
> 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.
>
> XHR without setRequestHeader sends usual 'GET' request:
>
> Request URL: http://zip.elevenbasetwo.com/?zip=a
> Request Method: GET
> Status Code: 404 Not Found
> Request Headers
> Accept: */*
> Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.3
> Accept-Encoding: gzip,deflate,sdch
> Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
> Connection: keep-alive
> Host: zip.elevenbasetwo.com
> Origin: https://groups.google.com
> User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19
> Response Headers
> Access-Control-Allow-Origin: *
> Connection: close
> Content-Type: text/plain
> Date: Fri, 13 Apr 2012 09:16:07 GMT
> Server: BaseHTTP/0.3 Python/2.7.1+
>
> XHR with any setRequestHeader sends first 'OPTIONS' request (so-called preflight):
>
> Request URL: http://zip.elevenbasetwo.com/?zip=a
> Request Method: OPTIONS
> Status Code: 501 Not Implemented
> Request Headers
> Accept: */*
> Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.3
> Accept-Encoding: gzip,deflate,sdch
> Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4
> Access-Control-Request-Headers: x-xxx, origin
> Access-Control-Request-Method: GET
> Connection: keep-alive
> Host: zip.elevenbasetwo.com
> Origin: https://groups.google.com
> User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19
> Response Headers
> Connection: close
> Content-Type: text/html
> Date: Fri, 13 Apr 2012 09:20:32 GMT
> Server: BaseHTTP/0.3 Python/2.7.1+
>
> It seems that some browsers (like Firefox and WebKit-based) may send CORS requests without preflight for text/plain resources when no additional headers are set. In other cases they send preflighted 'OPTIONS' request, which is not implemented in this 'BaseHTTP/0.3 Python/2.7.1+' server.
>
> --
> 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/-/6xIQrvgSIqsJ.