【问题标题】:JSONRequest.get sample codeJSONRequest.get 示例代码
【发布时间】:2012-12-14 21:20:51
【问题描述】:

这是我第一次使用 JSON,我是 web 开发中的菜鸟。在他们的网站 (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>

【问题讨论】:

  • 欢迎来到 SO。请提供更多关于您想要做什么的信息。此外,如果您提供一些您已经尝试过的代码,您更有可能获得问题的高质量答案。这里不是人们为你建造东西的地方,而是改进你已经尝试过的东西。

标签: javascript json get


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    来源: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 验证参数后,将排队 请求并返回请求号。完成的函数值将是 稍后在知道请求的结果时调用。

    没有 cookie 或隐式身份验证信息与 GET 一起发送 手术。任何认证信息都必须放在url中。

    请求可以使用 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
    

    【讨论】:

    • 如何在html中指定“Content-Type: application/jsonrequest”?我试过 但没有用
    猜你喜欢
    • 2011-04-23
    • 2011-12-17
    • 2016-12-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多