JSONRequest.get示例代码

时间:2012-12-14 21:20:51

标签: javascript json get

这是我第一次在网页开发中使用JSON和i noobie。在他们的网站(http://www.json.org/JSONRequest.html)上,他们建议使用JSONRequest.get。 但是,我一直收到错误" JSONRequest未定义"。我的代码如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<meta Content-Type= application/jsonrequest >

<title>Insert Events Page</title>
</head>
<body> 

<h2>List of ALL events: </h2><br>
<script type="text/javascript">
try {
    JSONRequest.get("http://localhost:8888/mma/event/allevents", function(sn, response, exception){
            alert(exception || response);
    });
}
catch(e) {
    alert(e);
}
</script>

</body>
</html>

2 个答案:

答案 0 :(得分:2)

您需要包含包含JSONRequest对象的文件。我不知道是否是官方网站,但可以从https://code.google.com/p/web-opm/source/browse/js/json/?name=client&r=f7c9a4447ed55570b0b056bbb90e82d310fb986f

下载

答案 1 :(得分:0)

这直接来自您引用的网站:

来源:http://www.json.org/JSONRequest.html

  

示例:

requestNumber = JSONRequest.get(
    "https://json.penzance.org/request",
    function (requestNumber, value, exception) {
        if (value) {
            processResponse(value);
        } else {
            processError(exception);
        }
    }
); 
     

在JSONRequest.get验证了参数之后,它将对队列进行排队   请求并返回请求编号。完成的函数值将是   稍后在请求结果已知时调用。

     

GET不会发送任何Cookie或隐式身份验证信息   操作。任何身份验证信息都必须放在网址中。

     

请求可以使用http或https。这个选择是独立的   页面的安全性。

GET /request HTTP/1.1
Accept: application/jsonrequest
Host: json.penzance.org
     

服务器确认请求后,它一直持续到   超时间隔到期以产生响应。如果时间限制是   超出,或者在完整响应之前关闭连接   发送,然后请求失败。

HTTP/1.1 200 OK
Content-Type: application/jsonrequest
Content-Length: xxxx