2

我正在使用这个 API,它将源自 LHR 的航班状态返回给 MAN(只是一个示例)。响应格式为 XML,但我无法使用 JavaScript 读取它。

我尝试了以下方法:

function loadXMLDoc(dname) { //the dname here is the url
    if (window.XMLHttpRequest) {
        xhttp = new XMLHttpRequest();
    } else {
        xhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xhttp.open("GET", dname, false);
    xhttp.send();
    return xhttp.responseXML;
}

但它不起作用。是否有另一种方法来读取 API 的 XML 响应?

4

1 回答 1

3

You could use jQuery and then make your ajax call using jQuery.ajax()

The code might look something like this...

    $.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        url: url,
        data: JSON.stringify(data),
        dataType: "json",
        error: function (response) {
            alert('Error: There was a problem processing your request, please refresh the browser and try again');
        },
        success: function (response) {
            if (response !== undefined && response !== null) {
               /* Evaluate the SOAP response object here */
            }
        }
    });
于 2013-08-06T16:56:33.390 回答