weixin_33737774 2014-02-19 15:13 采纳率: 0%
浏览 37

通过jQuery Ajax获取XML

I'm trying to GET xml from a server by using jquery ajax. I can get it working if I host an xml file (containing the same xml data) somewhere myself, but when I try to get it from the (target) server, I receive no data. But if I put the server url in my browser I do get the xml, so the url is fine.

My code:

$.ajax({
    async: false,
    type:"GET",
    url: url,
    crossDomain: true,
    data: "user=user1&password=password1&id=2",
    dataType:"xml",
    success: function(data) { alert(data);},
    error: function(event, jqXHR, ajaxSettings, thrownError) {
        console.log(JSON.stringify(event, null, 4));
        console.log(JSON.stringify(jqXHR, null, 4));
        console.log(JSON.stringify(ajaxSettings, null, 4));
        console.log(JSON.stringify(thrownError, null, 4));
        console.log(JSON.stringify(this, null, 4));
    },

How do I debug this? The GET request returns a statuscode 200:OK. The response headers show a content-length of 22194, but I get no response body? The output I get from the console logging is:

"{
    "readyState": 0,
    "status": 0,
    "statusText": "[Exception... \"Failure\"  nsresult: \"0x80004005 (NS_ERROR_FAILURE)\"  location: \"JS frame :: http://myownurl.com/jquery.js :: .send :: line 8526\"  data: no]"
}"
""error""
"{}"
undefined
"{
    "url": "http://targeturl.com/api/get?user=user1&password=password1&id=2",
    "type": "GET",
    "isLocal": false,
    "global": true,
    "processData": true,
    "async": false,
    "contentType": "application/x-www-form-urlencoded; charset=UTF-8",
    "accepts": {
        "*": "*/*",
        "text": "text/plain",
        "html": "text/html",
        "xml": "application/xml, text/xml",
        "json": "application/json, text/javascript",
        "script": "text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"
    },
    "contents": {
        "xml": {},
        "html": {},
        "json": {},
        "script": {}
    },
    "responseFields": {
        "xml": "responseXML",
        "text": "responseText"
    },
    "converters": {
        "text html": true
    },
    "flatOptions": {
        "url": true,
        "context": true
    },
    "jsonp": "callback",
    "crossDomain": true,
    "dataType": "xml",
    "dataTypes": [
        "xml"
    ],
    "hasContent": false
}"

(I'm not sure if it makes any difference, but I'm trying this in FireFox)

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 在若依框架下实现人脸识别
    • ¥15 网络科学导论,网络控制
    • ¥100 安卓tv程序连接SQLSERVER2008问题
    • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
    • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
    • ¥15 关于arduino编程toCharArray()函数的使用
    • ¥100 vc++混合CEF采用CLR方式编译报错
    • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
    • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
    • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同