1
function loaded() {
    var xmldoc,
    currenttime = new Date().getTime(),
    req,
    address = 'http://webservices.foo.com/eSignalQuotes/eSignalQuotes.asmx/GetDelayedQuotes?',
    symbols = 'symbols=' + '+c,s,ct,zw,kw,adm+', 
    cusip = '&cusip=',
    fields = '&fields=' + 'desc,month,year,recent,netchg,-decimal',
    type = '&type=' + 'future,stock,index',
    dispfullname = '&dispfullname=' + 'true',
    datefmt = '&datefmt=',
    timefmt = '&timefmt=',
    timestamp = '&' + Math.floor(currenttime/3600000),
    query = address + symbols + cusip + fields + type + dispfullname + datefmt + timefmt + timestamp;
    ;

    if(window.XMLHttpRequest) {
        req = new XMLHttpRequest();
    } else {
        req = new ActiveXObject("Microsoft.XMLHTTP");
    }

    req.addEventListener('error', function(e) {alert('Error');}, false);
    req.addEventListener('load', function(e) {xmldoc = req.responseText;}, false);
    req.open('GET', query, true);
    req.send();

}

それが私のコードのようで、SafariとFirefoxでは常にエラーが発生します。クレイジーなことは、イベントリスナーを削除し、応答タイプをに変更するとresponseText、InternetExplorerが出力を表示することです。私は試しoverrideMimetypeましたが、それは役に立たなかったようです。FirefoxまたはSafariで応答を確認すると、が表示されますnull。私は途方に暮れています、そしてどんな助けもいただければ幸いです。

このためにサードパーティのライブラリを避けたいと思います。

更新:エラーはprogressイベント中に発生します。確認する.lengthComputableと、false

アップデート2:Safariはこの問題にさらに光を当てます:

XMLHttpRequest cannot load Origin is not allowed by Access-Control-Allow-Origin.
4

1 に答える 1

0

100%確信は持てませんが、問題はサイト間のコミュニケーションに関係しているように思われます。最終的には、PHPスクリプトでファイルをダウンロードしてから、javascriptを使用してローカルで取得しました。

<?php
    $mark = $_GET['mark'];
    $xmldoc = new DOMDocument();
    $xmldoc -> preserveWhiteSpace = false;
    $xmldoc -> formatOutput = true;
    $xmldoc -> load($mark);
    unlink('fenced.xml');   
    echo $xmldoc -> save('fenced.xml');
?>

Javascript:

localreq.open('GET', 'fenced.xml', true);
localreq.addEventListener('load', function(e) {xmldoc = localreq.responseXML;}, false);
localreq.send();
于 2012-10-08T19:37:33.890 に答える