Quantcast
Channel: Appcelerator Developer Center Q&A Tag Feed (getresponseheader)
Viewing all articles
Browse latest Browse all 5

getResponseHeader not working in onreadystatechange function

$
0
0

Hi Community,

Is there any possibility to use getResponseHeader("Last-Modified") function in the onreadystatechange function? I tried it but I am getting NULL in response!

What I wanted to achieve is, download resource from server only if it has been modified since its last download.

var xhr = Titanium.Network.createHTTPClient();
 
xhr.onreadystatechange = function(e)
{
    switch(this.readyState)
    {
        case 0:
            // after HTTPClient declared, prior to open()
                        // though Ti won't actually report on this readyState
                        Ti.API.info('case 0, readyState = ' + this.readyState);
                        break;
        case 1:
                        // open() has been called, now is the time to set headers
                        Ti.API.info('case 1, readyState = ' + this.readyState);
                        break;
        case 2:
                        // headers received, xhr.status should be available now
                        Ti.API.error(JSON.stringify(this.getResponseHeader("Last-Modified")));
                        Ti.API.info('case 2, readyState = ' + this.readyState);
                        break;
        case 3:
                        // data is being received, onsendstream/ondatastream
                        // being called now
                        Ti.API.info('case 3, readyState = ' + this.readyState);
                        break;
        case 4:
                        // done, onload or onerror should be called now
                        Ti.API.info('case 4, readyState = ' + this.readyState);
                        break;
    }
};
 
xhr.open('GET', 'http://goo.gl/6IeXJ');
 
xhr.send();
Output log:
[INFO] :   case 1, readyState = 1
[ERROR] :  <null>
[INFO] :   case 2, readyState = 2
[INFO] :   case 3, readyState = 3
[INFO] :   case 4, readyState = 4
Environment Info:

Titanium SDK: 3.0.2.GA.5a77fe7 Platform: iOS OS: Mac Device: iOS Simulator Titanium Studio, build: 3.0.2.201302191606

Thanks in advance.


Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images