Cross Javascript Queries in IE8

I have a function that verifies an ID against a database. If the ID is found, the function returns true and if not it returns false.

Got the request to work in the other browsers. Now working on figuring it out with Internet Explorer’s XDomainRequest.

function verify(id){
    xmlhttp=new window.XDomainRequest();
    xmlhttp.onload = checkResponse;"GET", "" + encodeURIComponent(id));

    function checkResponse(){
        if(xmlhttp.responseText == 200) {
            return true;
        } else {
            return false;

The problem is that I want the verify function to return false, not the checkResponse function.

In other browsers setting the open to false does the trick but not in IE.

No jQuery answers please.

Thanks for your help!

Here is the recommended way to incorporate CORS requests in IE8 into jQuery. You could probably use this as a starting point for your own:

Also, verify
shouldn’t be a synchronous operation. Would recommend passing a callback function to it and keeping it async:

function verify(id, callback){
    var xmlhttp = new window.XDomainRequest();
    xmlhttp.onload = function () {
        callback( xmlhttp.responseText === 200 );
    };"GET", "" + encodeURIComponent(id));

Which you could then call like so:

verify( 123456, function ( isValid ) {
    if ( isValid ) {
        // do something if valid
    } else {
        // or not
Hello, buddy!责编内容来自:Hello, buddy! (源链) | 更多关于

本站遵循[CC BY-NC-SA 4.0]。如您有版权、意见投诉等问题,请通过eMail联系我们处理。
酷辣虫 » 前端开发 » Cross Javascript Queries in IE8

喜欢 (0)or分享给?

专业 x 专注 x 聚合 x 分享 CC BY-NC-SA 4.0

使用声明 | 英豪名录