语法错误:JSON.parse:在行JSON数据的第1列1意外的字符在行、字符、意外、语法错误

2023-09-11 00:47:40 作者:﹏北极星的泪彡

我已经花了6小时,发现异常或特殊字符来找到我的code,但我不能。我在这里仔细检查每一个类似的消息。

I've spend over 6 hours to find an exception or a special character to find in my code but I couldn't. I checked every similar messages in here.

我要送与庄重弹出的形式。首先我使用内联弹出打开自己的状态比我送的所有输入到main.js验证。

I'm sending the form with magnific popup. First I'm using inline popup to open my form than I'm sending all inputs to main.js to validate.

所以,我只是需要一个第三眼。

So, I just need a third-eye.

我有: index.html的 register.php 为主。 JS

这里的code

FORM

JS / AJAX

PHP-register.php

这里所说的错误信息

JSON输出的

JSON Output

Chrome浏览器控制台:

火狐控制台:

Firefox console :

我在想什么?

推荐答案

字符的是一个<让我觉得你有一个PHP错误,你有没有尝试过呼应的所有错误。

The fact the character is a < make me think you have a PHP error, have you tried echoing all errors.

由于我没有你的数据库,我要通过你的code试图发现错误,到目前为止,我已经更新了你的JS文件

Since I don't have your database, I'm going through your code trying to find errors, so far, I've updated your JS file

$("#register-form").submit(function (event) {

    var entrance = $(this).find('input[name="IsValid"]').val();
    var password = $(this).find('input[name="objPassword"]').val();
    var namesurname = $(this).find('input[name="objNameSurname"]').val();
    var email = $(this).find('input[name="objEmail"]').val();
    var gsm = $(this).find('input[name="objGsm"]').val();
    var adres = $(this).find('input[name="objAddress"]').val();
    var termsOk = $(this).find('input[name="objAcceptTerms"]').val();

    var formURL = $(this).attr("action");


    if (request) {
        request.abort(); // cancel if any process on pending
    }

    var postData = {
        "objAskGrant": entrance,
        "objPass": password,
        "objNameSurname": namesurname,
        "objEmail": email,
        "objGsm": parseInt(gsm),
        "objAdres": adres,
        "objTerms": termsOk
    };

    $.post(formURL,postData,function(data,status){
        console.log("Data: " + data + "\nStatus: " + status);
    });

    event.preventDefault();
});

PHP编辑:

PHP

 if (isset($_POST)) {

    $fValid = clear($_POST['objAskGrant']);
    $fTerms = clear($_POST['objTerms']);

    if ($fValid) {
        $fPass = clear($_POST['objPass']);
        $fNameSurname = clear($_POST['objNameSurname']);
        $fMail = clear($_POST['objEmail']);
        $fGsm = clear(int($_POST['objGsm']));
        $fAddress = clear($_POST['objAdres']);
        $UserIpAddress = "hidden";
        $UserCityLocation = "hidden";
        $UserCountry = "hidden";

        $DateTime = new DateTime();
        $result = $date->format('d-m-Y-H:i:s');
        $krr = explode('-', $result);
        $resultDateTime = implode("", $krr);

        $data = array('error' => 'Yükleme Sırasında Hata Oluştu');

        $kayit = "INSERT INTO tbl_Records(UserNameSurname, UserMail, UserGsm, UserAddress, DateAdded, UserIp, UserCityLocation, UserCountry, IsChecked, GivenPasscode) VALUES ('$fNameSurname', '$fMail', '$fGsm', '$fAddress', '$resultDateTime', '$UserIpAddress', '$UserCityLocation', '$UserCountry', '$fTerms', '$fPass')";
        $retval = mysql_query( $kayit, $conn ); // Update with you connection details
            if ($retval) {
                $data = array('success' => 'Register Completed', 'postData' => $_POST);
            }

        } // valid ends
    }echo json_encode($data);