簡體   English   中英

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

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

嘿,我認為我的php編碼有問題,我正在收到SyntaxError:意外的標記<在JSON中的位置0

在jquery ajax表單發布的成功部分中。 的PHP代碼送我回來

<?



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

的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;

    ?>

我不知道為什么即時通訊得到它給出的響應。 請幫忙

由於此文件使用<?php而不僅僅是<? 作為開始標簽,輸出來自另一個文件。 您可以找到該文件並刪除這5行,或者啟用短標簽(請參閱如何啟用PHP短標簽? )。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM