2

加载网页时,我在 Firebug 中收到以下错误:

redirect.processBrowser is not a function
[Break On This Error]   
url = redirect.processBrowser(JSON.stringify(browserInfo));

在 Firebug 中看到的响应如下:

{"transport":"POST","envelope":"JSON-RPC-2.0","contentType":"application\/json","SMDVersion":"2.0","target":"\/json-rpc.php","services":{"processBrowser":{"envelope":"JSON-RPC-2.0","transport":"POST","parameters":[{"type":"object","name":"json","optional":false}],"returns":"string"}},"methods":{"processBrowser":{"envelope":"JSON-RPC-2.0","transport":"POST","parameters":[{"type":"object","name":"json","optional":false}],"returns":"string"}}}{"error":{"code":-32600,"message":"Invalid Request","data":null},"id":null}

代码的javascript如下:

<script src="js/jquery-1.7.2.min.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>
<script src="js/jquery.zend.jsonrpc.js" type="text/javascript"></script>
<script src="js/browserDetect.js" type="text/javascript"></script>
<script type="text/javascript">
        $(document).ready(function()
        {
            browserInfo = {
                "screen_width": screen.width,
                "screen_height": screen.height,
                "color_depth": screen.colorDepth,
                "url": document.URL,
                "user_agent": navigator.userAgent,
                "browser_name": BrowserDetect.browser,
                "browser_version": BrowserDetect.version,
                "platform": BrowserDetect.OS
            };

            redirect = jQuery.Zend.jsonrpc({url: '/json-rpc.php'});

            url = redirect.processBrowser(JSON.stringify(browserInfo));

            window.location.replace(url);
        });
    </script>

jsonrpc.php 代码如下:

<?php
// Define path to the application directory
defined('REFERRAL_SYSTEM_ROOT') || define('REFERRAL_SYSTEM_ROOT', realpath('/system'));
defined('REFERRAL_PUBLIC_ROOT') || define('REFERRAL_PUBLIC_ROOT', realpath('/public'));

require_once REFERRAL_SYSTEM_ROOT . '/some_file.php';

/**
 * Zend Application
 **/
require_once 'Zend/Application.php';

// Create application, bootstrap, and run
$application = new Zend_Application($_ENV["REFERRAL_ENVIRONMENT"], REFERRAL_SYSTEM_ROOT . '/config/application.ini');

$application->getBootstrap();

require_once 'Browser.php';

// Instantiate server, etc.
$server = new Zend_Json_Server();
$server->setClass('Browser');

if('GET' == $_SERVER['REQUEST_METHOD'])
{
    // Indicate the URL endpoint, and the JSON-RPC version used:
    $server->setTarget('/jsonrpc.php')
           ->setEnvelope(Zend_Json_Server_Smd::ENV_JSONRPC_2);

    // Grab the SMD
    $smd = $server->getServiceMap();

    // Return the SMD to the client
    header('Content-Type: application/json');
    echo $smd;
}

$server->handle();

正如您从响应中看到的,ZEND_JSON_RPC 服务器看到了 processBrowser,但我得到了“不是函数”响应。我不知道为什么会这样。

有什么想法吗?

编辑-> 2012 年 4 月 26 日 @ 美国东部时间下午 4:25

虽然函数processBrowser()确实存在,但它是Browser.php中定义的Browser类的一部分,调用jQuery.Zend.jsonrpc({url: '/json-rpc.php'})显然没有收到正确的回复。我仍然不知道为什么。

4

2 回答 2

1

我把你说的来自萤火虫控制台的 json 和 jsonlint 拿走了。

结果如下: Parse error on line 35: ...g" ​​} }}{ "error": {
--------------------^ Expecting 'EOF' , '}', ',', ']'

在错误部分之前,您有整个响应的右括号。我不确定是什么产生了响应,但需要将其从那里移除并将其放在最后。

这是更正的json:

{ “传输”:“POST”,“信封”:“JSON-RPC-2.0”,“contentType”:“application/json”,“SMDVersion”:“2.0”,“target”:“/json-rpc.php ”,“服务”:{“processBrowser”:{“信封”:“JSON-RPC-2.0”,“传输”:“POST”,“参数”:[{“类型”:“对象”,“名称”: "json", "optional": false}], "returns": "string" } }, "methods": { "processBrowser": { "envelope": "JSON-RPC-2.0", "transport": "POST", "参数": [{ "type": "object", "name": "json", "optional": false}], "returns": "string" } } { "error": { "code ": -32600, "message": "无效请求", "data": null }, "id": null } };“数据”:空},“ID”:空}};“数据”:空},“ID”:空}};

于 2012-04-26T19:50:37.410 回答
0

我有同样的问题。尝试删除行“ header('Content-Type: application/json');”。它对我有用:)

于 2012-05-07T05:13:06.820 回答