【发布时间】:2013-06-15 07:24:47
【问题描述】:
我正在尝试使用 GET HTTP cal,我收到了使用高级 REST 客户端 (Chrome plugin) 的请求,但无法让它在 JQuery 中工作。
根据this thread 的建议,我设置了以下内容:
$(document).ready(function() {
$('.ap1').click(function(){
$.ajax({
url: 'https://api2.panopta.com/v2/monitoring_node/41',
type: 'GET',
dataType: 'json',
success: function() { alert('hello!'); },
error: function() { alert('boo!'); },
beforeSend: setHeader
});
});
function setHeader(xhr) {
//extra stuff from REST CLIENT
xhr.setRequestHeader('Authorization', 'ApiKey nGhhAjGshbOu4dhLYvGY');
} });
这是我想要得到的输出(使用 REST 客户端成功)
{
url: "https://api2.panopta.com/v2/monitoring_node/41"
hostname: "phoenix01.monitorengine.com"
ip_address: "65.23.158.149"
name: "Phoenix"
textkey: "na.west.phoenix01"
}
我只想能够从该 JSON 中访问 name 变量并将其传递给我的函数。在我试图弄清楚如何创建一个对象之前,我想至少让上面的代码工作,这样我就可以成功地调用这个名字,比如.append(object.name)
我刚开始学习 JQuery,这是我的第一篇文章,如果我没有包含足够的细节,非常抱歉。
【问题讨论】: