Php JavaScript返回";不是一个函数;错误,但该方法已在Firebug的响应中列出
加载网页时,Firebug中出现以下错误:Php JavaScript返回";不是一个函数;错误,但该方法已在Firebug的响应中列出,php,javascript,json,zend-framework,json-rpc,Php,Javascript,Json,Zend Framework,Json Rpc,加载网页时,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","SM
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}
<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>
<?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();
代码的javascript如下所示:
{"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}
<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>
<?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();
$(文档).ready(函数()
{
browserInfo={
“屏幕宽度”:屏幕宽度,
“屏幕高度”:屏幕高度,
“颜色深度”:screen.colorDepth,
“url”:document.url,
“用户代理”:navigator.userAgent,
“浏览器名称”:BrowserDetect.browser,
“浏览器版本”:BrowserDetect.version,
“平台”:BrowserDetect.OS
};
redirect=jQuery.Zend.jsonrpc({url:'/json-rpc.php'});
url=redirect.processBrowser(JSON.stringify(browserInfo));
window.location.replace(url);
});
jsonrpc.php代码如下所示:
{"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}
<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>
<?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();
我从firebug控制台获取了您所说的json,然后jsonlint它
结果如下:
第35行的分析错误:
…g“}}{”错误:{
--------------------^
应为'EOF'、'}'、'、'、']'
在错误部分之前,您有整个响应的结束括号。我不确定是什么生成了响应,但需要从那里删除它并将其放在末尾
这是json更正的错误:
{
“运输”:“邮政”,
“信封”:“JSON-RPC-2.0”,
“contentType”:“application/json”,
“SMDVersion”:“2.0”,
“目标”:“/json rpc.php”,
“服务”:{
“processBrowser”:{
“信封”:“JSON-RPC-2.0”,
“运输”:“邮政”,
“参数”:[{
“类型”:“对象”,
“名称”:“json”,
“可选”:false}],
“返回”:“字符串”
}
},
“方法”:{
“processBrowser”:{
“信封”:“JSON-RPC-2.0”,
“运输”:“邮政”,
“参数”:[{
“类型”:“对象”,
“名称”:“json”,
“可选”:false}],
“返回”:“字符串”
}
}
{
“错误”:{
“代码”:-32600,
“消息”:“无效请求”,
“数据”:空
},
“id”:空
}
}我也遇到了同样的问题。请尝试删除行“标题('Content-Type:application/json');
”。它对我有效:)您收到了错误消息,因为它不是函数。请尝试使用控制台.log(重定向)
自己看看。虽然函数确实存在,但当jQuery.Zend.jsonrpc({url:'/json rpc.php})运行时,JavaScript似乎没有返回正确的结果;被调用。你是说FireFox错了吗?如果JSON响应格式不正确,或者某个JS文件无法加载或解析,那么它就不存在。Lee,当然我不是说FireFox错了。我是说在PHP中的Browser
类中定义了一个名为processBrowser()的公共函数
,但是JavaScript没有正确加载它。我遇到的问题是为什么JS没有得到正确的响应?