| 522 | | var errorNotHandled=true; |
|---|
| 523 | | try{ |
|---|
| 524 | | var xmlhttp = mod.getHTTPRequestObject(); |
|---|
| 525 | | }catch(e){ |
|---|
| 526 | | cb(null, new mod.LoadURIFailed(uri, new mod.Exception(uri,e))); |
|---|
| 527 | | return; |
|---|
| 528 | | } |
|---|
| 529 | | |
|---|
| 530 | | xmlhttp.onreadystatechange=function(){ |
|---|
| 531 | | if (xmlhttp.readyState==4) { |
|---|
| 532 | | //todo: the status checking needs testing |
|---|
| 533 | | if(xmlhttp.status == 200 || xmlhttp.status == 0 || xmlhttp.status == null || xmlhttp.status == 304){ |
|---|
| 534 | | var s= str(xmlhttp.responseText); |
|---|
| 535 | | xmlhttp = null; |
|---|
| 536 | | cb(s); |
|---|
| 537 | | }else{ |
|---|
| 538 | | if(errorNotHandled){ |
|---|
| 539 | | errorNotHandled=false; |
|---|
| 540 | | cb(null, new mod.LoadURIFailed(uri, new mod.Exception("Server did not respond with status code 200 but with: " + xmlhttp.status))); |
|---|
| 541 | | } |
|---|
| 542 | | } |
|---|
| 543 | | xmlhttp=null; |
|---|
| 544 | | }else if (xmlhttp.readyState==2){ |
|---|
| 545 | | //status property should be available (MS IXMLHTTPRequest documentation) |
|---|
| 546 | | //in Mozilla it is not if the request failed(server not reachable) |
|---|
| 547 | | //in IE it is not available at all ?! |
|---|
| 548 | | try{//see if it is mozilla otherwise don't care. |
|---|
| 549 | | var isNetscape = netscape; |
|---|
| 550 | | try{//if status is not available the request failed. |
|---|
| 551 | | var s=xmlhttp.status; |
|---|
| 552 | | }catch(e){//call the callback because Mozilla will not get to readystate 4 |
|---|
| | 522 | // IE7 is shite or I am an idiot |
|---|
| | 523 | // it looks like it calls onreadystatechange before returning from the send() call |
|---|
| | 524 | // for urls that are cached, thus making the call sync and not async. |
|---|
| | 525 | // this is clearly wrong !!! |
|---|
| | 526 | //so we emulate everything using a setTimeout ... ugh |
|---|
| | 527 | setTimeout(function(){ |
|---|
| | 528 | |
|---|
| | 529 | var errorNotHandled=true; |
|---|
| | 530 | try{ |
|---|
| | 531 | var xmlhttp = mod.getHTTPRequestObject(); |
|---|
| | 532 | }catch(e){ |
|---|
| | 533 | cb(null, new mod.LoadURIFailed(uri, new mod.Exception(uri,e))); |
|---|
| | 534 | return; |
|---|
| | 535 | } |
|---|
| | 536 | |
|---|
| | 537 | xmlhttp.onreadystatechange=function(){ |
|---|
| | 538 | if (xmlhttp.readyState==4) { |
|---|
| | 539 | //todo: the status checking needs testing |
|---|
| | 540 | if(xmlhttp.status == 200 || xmlhttp.status == 0 || xmlhttp.status == null || xmlhttp.status == 304){ |
|---|
| | 541 | var s= str(xmlhttp.responseText); |
|---|
| | 542 | xmlhttp = null; |
|---|
| | 543 | cb(s); |
|---|
| | 544 | }else{ |
|---|
| 559 | | }catch(e){ |
|---|
| 560 | | } |
|---|
| 561 | | } |
|---|
| 562 | | }; |
|---|
| 563 | | |
|---|
| 564 | | try{ |
|---|
| 565 | | xmlhttp.open("GET", uri, true); |
|---|
| 566 | | xmlhttp.send(""); |
|---|
| 567 | | }catch(e){ |
|---|
| 568 | | if(errorNotHandled){ |
|---|
| 569 | | errorNotHandled=false; |
|---|
| 570 | | xmlhttp=null; |
|---|
| 571 | | cb (null, new mod.LoadURIFailed(uri, e)); |
|---|
| 572 | | } |
|---|
| 573 | | } |
|---|
| | 550 | xmlhttp=null; |
|---|
| | 551 | }else if (xmlhttp.readyState==2){ |
|---|
| | 552 | //status property should be available (MS IXMLHTTPRequest documentation) |
|---|
| | 553 | //in Mozilla it is not if the request failed(server not reachable) |
|---|
| | 554 | //in IE it is not available at all ?! |
|---|
| | 555 | try{//see if it is mozilla otherwise don't care. |
|---|
| | 556 | var isNetscape = netscape; |
|---|
| | 557 | try{//if status is not available the request failed. |
|---|
| | 558 | var s=xmlhttp.status; |
|---|
| | 559 | }catch(e){//call the callback because Mozilla will not get to readystate 4 |
|---|
| | 560 | if(errorNotHandled){ |
|---|
| | 561 | xmlhttp = null; |
|---|
| | 562 | errorNotHandled=false; |
|---|
| | 563 | cb(null, new mod.LoadURIFailed(uri, new mod.Exception("url request failed ",e))); |
|---|
| | 564 | } |
|---|
| | 565 | } |
|---|
| | 566 | }catch(e){ |
|---|
| | 567 | } |
|---|
| | 568 | } |
|---|
| | 569 | } |
|---|
| | 570 | |
|---|
| | 571 | |
|---|
| | 572 | try{ |
|---|
| | 573 | xmlhttp.open("GET", uri, true); |
|---|
| | 574 | xmlhttp.send(""); |
|---|
| | 575 | }catch(e){ |
|---|
| | 576 | if(errorNotHandled){ |
|---|
| | 577 | errorNotHandled=false; |
|---|
| | 578 | xmlhttp=null; |
|---|
| | 579 | cb (null, new mod.LoadURIFailed(uri, e)); |
|---|
| | 580 | } |
|---|
| | 581 | } |
|---|
| | 582 | },0); |
|---|