解析PHP回应:未捕获的SyntaxError:意外的标记< [英] Parsing PHP response: Uncaught SyntaxError: Unexpected token <

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

问题描述

我使用AJAX来打电话到一个PHP脚本。我需要从响应解析的唯一事情是由脚本生成一个随机ID。问题是,PHP脚本抛出一些错误。这些错误实际上是很好,没有得到的程序功能的方法。唯一的问题是,当我运行

I'm using AJAX to make a call to a PHP script. The only thing I need to parse from the response is a random ID generated by the script. The problem is that the PHP script throws a number of errors. The errors are actually fine and don't get in the way of the program functionality. The only issue is that when I run

$.parseJSON(response)

我得到:

Uncaught SyntaxError: Unexpected token < 

由于PHP响应与错误启动:

Since the PHP response starts with an error:

<br /> 
<b>Warning</b>:

我不知道如何更改PHP或JS,使得它能够解析出ID,尽管错误。

I'm wondering how to change the PHP or JS such that it can parse out the ID despite the errors.

PHP:

  $returnData = array();
  $returnData['id'] = $pdfID;
  echo json_encode($returnData); 
  ...

记者:

 function returnReport(response) {
    var parsedResponse = $.parseJSON(response);
    console.log(parsedResponse);
    pdfID = parsedResponse['id']; 

我知道的警告应该可以解决,但警告不是现在,更重要的功能至关重要的。

I know that the warnings should be resolved, but the warnings are not functionality critical for now and more importantly

1)即使这些警告都解决了新的可能出现上下行和JSON仍然应该正确分析和

1) Even if these warnings are resolved new ones may come up down the line and the JSON should still be properly parsed and

2)除了警告有告示导致相同的问题。

2) In addition to the warnings there are 'notices' that cause the same issue.

推荐答案

为什么不处理,消除了警告,使来自服务器的结果实际上是JSON?

Why not deal with and eliminate the warning so that the result from the server is actually JSON?

这篇关于解析PHP回应:未捕获的SyntaxError:意外的标记&LT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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