加载网页时,我在 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'})显然没有收到正确的回复。我仍然不知道为什么。