dimanche 28 juin 2015

Can't Understand the XmlHttpRequest Code

First I should say I'm a beginner to XMLHttpRequest.

I Need to get a response from the below code that I didn't wrote.

But all I get is objectXMLHttpRequest.

How Can I find out if this function is returning true or false : actually the URL is for a PHP page that will return true or false.

function :

syncRequest:function(method, uri, checkTime, timeStamp, timeInterval)
{
    //if(this.checkUSBAccess(uri))
    {
        var usbParam = 0;//USBToken.getUSBTokenUrl();
        if(usbParam)
        {
            uri += usbParam;
        }
    }

    if (checkTime)
    {
        var d = new Date();
        if ((d.getTime() - timeStamp.getTime()) < (timeInterval*1000))
            return false;
    }
    var errorObj;
    var o = this.getConnectionObject();

    if(method == 'POST'){
        var splitedUri = uri.split('?');
        uri = splitedUri[0];
        var postData = splitedUri[1];
    }

    if(!o){
        return null;
    }
    else{
        var oConn = this;
        if(activeXSRFCode)
        {
            if(method == 'POST')
            {
                if(typeof postData != 'undefined' && postData.length > 0)
                {
                    postData = postData + '&XSRFCode='+ XSRFCode;
                }
                else
                {
                    postData = 'XSRFCode='+ XSRFCode;
                }
            }
            else
            {
                if (uri.indexOf('?') > 0)
                    uri += '&XSRFCode='+ XSRFCode;
                else
                    uri += '?XSRFCode='+ XSRFCode;

            }

        }
        o.conn.open(method, uri, false);

        if(postData){
            this.initHeader('Content-Type','application/x-www-form-urlencoded');
        }

        //Verify whether the transaction has any user-defined HTTP headers
        //and set them.
        if(this._http_header.length>0){
            this.setHeader(o);
        }
        postData?o.conn.send(postData):o.conn.send(null);

        if(activeXSRFCode)
        {
            try
            {
                var rText = eval(o.conn.responseText);
                XSRFCode = rText['XSRFCode'];
                var object1 = {};
                object1.responseText = '('+JSON.stringify(rText['data'])+')';
                return object1;
            }
            catch (e)
            {
                return o.conn;
            }
        }

        return o.conn;
    }
    object1.responseText = '('+JSON.stringify(rText['data'])+')';
    return object1;
},

this is how I want to get result :

$result=syncRequest('GET', url);
Utils.showMessage($result);//create a javascript box that will show the response

Aucun commentaire:

Enregistrer un commentaire