未捕获的SyntaxError:意外的令牌<在Chrome上 [英] Uncaught SyntaxError: Unexpected token < On Chrome

查看:139
本文介绍了未捕获的SyntaxError:意外的令牌<在Chrome上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经被问了很多次,但我无法找到与我的问题相似的地方。我只在Chrome中收到此错误,在其他所有浏览器中,一切正常。我在几个地方用JSON返回数据,但由于我的代码在其他浏览器中工作,我认为它没有任何问题。
Chrome浏览器不显示错误的位置(在我的代码中),它显示了这些错误:


这是我使用JSON的方式:

  $。post(getData.php,{'id':id},function(data){
var obj = jQuery.parseJSON );




...一些mysqli查询
$ data = $ query-> fetch_assoc();
echo json_encode($ data);

所以我在这里没有看到问题,有人可以帮忙 >使用@Mario的答案,但这只是我的问题的一部分,另一个问题是,JavaScript没有从PHP文件中获取任何数据,这是使用PHP代码中的代码解决的: header(Content -Type:text / javascript; charset = utf-8);
这个答案可以在这个链接上找到,我打开了一个其他问题来解决这个问题:在Chrome和Opera中无法从PHP接收json数据


I know this question has been asked many times but I can't find similarity with my issue. I'm getting this error only in Chrome, in every other browser everything is ok. I return data with JSON in several places but since my code works in other browsers I assume nothing is wrong with it. Chrome doesn't show me where is error (in my code) it shows me these errors:

This is how I use JSON:

$.post("getData.php", {'id' : id}, function(data){
        var obj = jQuery.parseJSON(data);
.
.
.

... some mysqli query
$data = $query->fetch_assoc();
echo json_encode($data);

So I don't see a problem here, can someone help me with this.

解决方案

Error with Uncaught SyntaxError: Unexpected token < using @Mario answer but that was only part of my problem. Another problem is, javascript doesn't get any data from PHP file. That was solved using this code, inside PHP file: header("Content-Type: text/javascript; charset=utf-8"); This answer is found on this link, where I opened another question to solve this issue: Can't receive json data from PHP in Chrome and Opera

这篇关于未捕获的SyntaxError:意外的令牌&lt;在Chrome上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆