小编P4t*_*4tR的帖子

使用JSONP时"无效标签"?

我的JSONP请求有问题..数据不会显示,Firebug显示"无效标签"错误.

在此输入图像描述

我的JavaScript:

$.ajax({
    url: link,
    dataType: "jsonp",
    beforeSend: function(xhr) {
        var base64 = btoa(username + ":" + password);
        xhr.setRequestHeader("Authorization", "Basic" + base64);
        xhr.overrideMimeType("application/json");
    },
    jsonpCallback: "getResources"
})

function getResources(data) {
    alert(data);
    alert(JSON.parse(data));
    $.each(data.groupStatus, function(i, item) {
        $("body").append("<p>ID: " + item.id + "</p>");
    });
}
Run Code Online (Sandbox Code Playgroud)

我的JSON:

{
    "groupStatus": [
        {
            "id": "Application Layer Configuration-ApplicationLayer",
            "time": 1332755316976,
            "level": 0,
            "warningIds": [],
            "errorIds": []
        },
        {
            "id": "Application Layer-ApplicationLayer:nscalealinst2",
            "time": 1333431531046,
            "level": 0,
            "warningIds": [],
            "errorIds": []
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的HTML:

<html>
<head> …
Run Code Online (Sandbox Code Playgroud)

javascript ajax json jsonp syntax-error

5
推荐指数
1
解决办法
3843
查看次数

JSON数据不会通过jQuerys getJSON()显示

以下代码应显示id我从服务器获取的JSON对象.我找不到错误,有人能帮帮我吗?先感谢您!

http://localhost:8387/nscalemc/rest/mon/resourcestatus.json调用时返回的JSON对象:

{
    "groupStatus": [
        {
            "id": "Application Layer Configuration-ApplicationLayer",
            "time": 1332755316976,
            "level": 0,
            "warningIds": [],
            "errorIds": []
        },
        {
            "id": "Application Layer-ApplicationLayer:nscalealinst2",
            "time": 1333431531046,
            "level": 0,
            "warningIds": [],
            "errorIds": []
        },
        {
            "id": "Application Layer-ApplicationLayer:nscalealinst1",
            "time": 1333431531046,
            "level": 1,
            "warningIds": [
                "documentarea.locked"
            ],
            "errorIds": []
        },
        {
            "id": "Storage Layer-StorageLayerInstance1",
            "time": 1331208543687,
            "level": 0,
            "warningIds": [],
            "errorIds": []
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我的HTML文件gadget.html:

<html>
<head>
    <title>Monitor</title>
    <link href="css/gadget.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="js/jquery-1.7.2.js"></script>
    <script …
Run Code Online (Sandbox Code Playgroud)

javascript jquery json

2
推荐指数
1
解决办法
1075
查看次数

标签 统计

javascript ×2

json ×2

ajax ×1

jquery ×1

jsonp ×1

syntax-error ×1