简体   繁体   English

SyntaxError:JSON位置0 php中的意外令牌<

[英]SyntaxError: Unexpected token < in JSON at position 0 php

hey there i have an issue with my php coding i think, i am getting SyntaxError: Unexpected token < in JSON at position 0 嘿,我认为我的php编码有问题,我正在收到SyntaxError:意外的标记<在JSON中的位置0

during the success part of a jquery ajax form post. 在jquery ajax表单发布的成功部分中。 the php code is sending me back 的PHP代码送我回来

<?



?>{"Status":"Login Success"}

the php code is as follows 的PHP代码如下

<?php
    header('Content-type: application/json');
    //Load DB Connection
    require('Global.php');
    require('dbConnect.php');
    require('Studio7WebClass.php');


    //Get form data
    $username = $_POST['user'];
    $password = $_POST['pass'];
    $returnJSON = array('Status'=>'');
    $finalJSON = "";
    $Studio7Current = new Studio7Web;

    $Studio7Current->set_username($username);

        try{
            $statement = $conn->prepare("select * from Users where (Username = :name OR EmailAddress = :name)");
            $statement->execute(array(':name' => $username));
            $row = $statement->fetch();

            if (is_null($row)){
                $returnJSON['Status'] = "User Not Found";
                    $finalJSON = json_encode($returnJSON);
            }
            else{

                //Now check if the password matches the one the user entered.
                if($row['password'] == $password){
                    //Passwords match
                    $returnJSON['Status'] = "Login Success";
                    $finalJSON = json_encode($returnJSON);

                }else{

                    $returnJSON['Status'] = "Password Error";
                    $finalJSON =  json_encode($returnJSON);
                }

            }



        }catch(PDOException $e){
            $returnJSON['Status'] =  $e->getMessage();
            $finalJSON =  json_encode($returnJSON);
            file_put_contents('PDOErrors.txt', $e->getMessage(), FILE_APPEND);

        }       

    echo $finalJSON;

    ?>

i have no idea why im getting the response it gives. 我不知道为什么即时通讯得到它给出的响应。 please help 请帮忙

Since this file uses <?php and not just <? 由于此文件使用<?php而不仅仅是<? as opening tags, the output comes from another file. 作为开始标签,输出来自另一个文件。 You could either find that file and remove those 5 lines, or enable short tags (see How to enable PHP short tags? ). 您可以找到该文件并删除这5行,或者启用短标签(请参阅如何启用PHP短标签? )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SyntaxError: Unexpected token &lt; in JSON at position 0 ajax ZE1BFD762321E409CEE4840 - SyntaxError: Unexpected token < in JSON at position 0 ajax php SyntaxError:位置4的JSON中的意外令牌&lt; - SyntaxError: Unexpected token < in JSON at position 4 语法错误:json 中位置 0 的意外标记 &lt; - syntaxerror : unexpected token < in json at position 0 发布到 PHP 时出现 HttpErrorResponse - SyntaxError: Unexpected token a in JSON at position 41 - HttpErrorResponse when posting to PHP - SyntaxError: Unexpected token a in JSON at position 41 SyntaxError:位于0的JSON中的意外标记&lt;Angular Post Request to PHP - SyntaxError: Unexpected token < in JSON at position 0 - Angular Post Request to PHP SyntaxError:JSON中位置1处的意外令牌s - SyntaxError: Unexpected token s in JSON at position 1 SyntaxError 问题:JSON 中位置 0 的意外标记 K - Problem with SyntaxError: Unexpected token K in JSON at position 0 错误语法错误:意外的令牌 &lt; 在 JSON 中位于离子 3 中的位置 0 - ERROR SyntaxError: Unexpected token < in JSON at position 0 in ionic 3 语法错误:JSON 中位置 0 的意外标记 I - SyntaxError: Unexpected token I in JSON at position 0 未捕获的语法错误:JSON 中的意外标记 D 位于位置 0 - Uncaught SyntaxError: Unexpected token D in JSON at position 0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM