Php 如何消除Firefox中的JSON错误
我的回复标题是Php 如何消除Firefox中的JSON错误,php,javascript,ajax,json,firefox,Php,Javascript,Ajax,Json,Firefox,我的回复标题是 Access-Control-Allow-Meth... GET, POST Access-Control-Allow-Orig... * Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Connection Keep-Alive Content-Length 81 Content-Type text/html Date Mon, 26 Aug
Access-Control-Allow-Meth... GET, POST
Access-Control-Allow-Orig... *
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection Keep-Alive
Content-Length 81
Content-Type text/html
Date Mon, 26 Aug 2013 06:35:53 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive timeout=5, max=99
Pragma no-cache
Server Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
X-Powered-By PHP/5.4.7`
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control no-cache
Connection keep-alive
Content-Length 31
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie USERNAMEEMAIL=shan%40atlos.com; PHPSESSID=8asm46iltcqc9oahsbaaap1c16
Host localhost
Pragma no-cache
Referer http://localhost/test/
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
X-Requested-With XMLHttpRequest`
请求头是
Access-Control-Allow-Meth... GET, POST
Access-Control-Allow-Orig... *
Cache-Control no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Connection Keep-Alive
Content-Length 81
Content-Type text/html
Date Mon, 26 Aug 2013 06:35:53 GMT
Expires Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive timeout=5, max=99
Pragma no-cache
Server Apache/2.4.3 (Win32) OpenSSL/1.0.1c PHP/5.4.7
X-Powered-By PHP/5.4.7`
Accept application/json, text/javascript, */*; q=0.01
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Cache-Control no-cache
Connection keep-alive
Content-Length 31
Content-Type application/x-www-form-urlencoded; charset=UTF-8
Cookie USERNAMEEMAIL=shan%40atlos.com; PHPSESSID=8asm46iltcqc9oahsbaaap1c16
Host localhost
Pragma no-cache
Referer http://localhost/test/
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0
X-Requested-With XMLHttpRequest`
我在firefox中遇到错误“格式不好”,这其中的问题是什么。
我以json格式正确地获取数据,但它也显示了一个非常烦人的错误
发出请求的Java脚本代码
并使用一个类来生成Ajax请求
您的响应标题不正确
if(headers_sent()) die('Should not output data before json');
header('Content-type: application/json');
echo json_encode($data_for_json);
exit;
此外,json之前不应发送任何内容,之后也不应发送任何内容
针对以下评论: 在php代码的某个地方,您正在输出json。但是,如上所述,您的响应头不正确:
内容类型
部分应设置为application/json
;上面的代码就是这样做的。逐行步行:
内容类型
部分设置为适当的mime类型更多更新irt评论 您正在手动创建json字符串:我可以全心全意地提出反对意见,使用数组或对象,然后使用json_encode创建json。 我还为代码添加了输出缓冲,以防万一 试一试,新的代码是
更新三 在work-space.js中,替换此行
self.responseValue = self.getValueFromResponse( jqXHR );
用这个
if(type != 'xml') self.responseValue = data;
else self.responseValue = self.getValueFromResponse( jqXHR );
保存它,清除缓存,然后重试。请发布给出错误的JSON。@MikeW我收到了回复
{“success”:“true”,“friends”:“0”,“notifications”:“0”,“messages”:“0”,“reirect”:“0”}
这是什么以及如何处理这些错误?评论空间不足,所以我更新了答案;希望这能帮你解决同样的问题,我是否应该以文本形式发布那个php文件的链接,这样你就可以看到那个文件了@vollie这里是我得到json格式响应的文件这是php文件,它作为json格式的响应,我通过javaScript/JQuery Ajax调用和html页面中的追加获得,工作正常,但在firefox中显示错误“格式不正确”,由于这个错误,一些功能停止,没有任何消息,但我知道它停止了