AJAX语法错误:JSON.parse:意外的字符 [英] AJAX SyntaxError: JSON.parse: unexpected character

查看:204
本文介绍了AJAX语法错误:JSON.parse:意外的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在试图找出问题,这几天。由于我的数据被发送和检索,但它并没有张贴到我的分区。为什么?我做了一个测试,发现我一个SyntaxError意想不到的角色。而且我可以找到它。可我心里很不舒服。

有人可以期待通过这一点,并告诉任何错误,我请。

 <脚本>
$(文件)。就绪(函数(){
    $(#形式mycommentform)。递交(函数(){

        VAR streamidcontent = $(本)。儿童(#streamidcontent)VAL()。
        。VAR内容= $(本)。儿童(#内容)VAL();
        $阿贾克斯({
            键入:POST,
            网址:comment_add.php
            缓存:假的,
            数据类型:JSON,
            数据:{streamidcontent:streamidcontent,内容:内容},
            成功:功能(数据){
                $(#containerid)HTML('< D​​IV CLASS =stream_comment_holderID =comment_holder _'+数据['comment_streamitem'] +'> \
                < D​​IV ID =comment_list _'+数据['comment_streamitem'] +'> \
                < D​​IV ID =TGY>< / DIV>< D​​IV CLASS =stream_commentID =评论_'+数据['COMMENT_ID'] +'的风格=的margin-top:0px;> \
                <表格的宽度= 100%GT;< TR>< TD VALIGN =顶宽= 30PX>< / A>< TD VALIGN =顶部对齐=左> \
                < A HREF =?/ profile.php用户名='+数据['用户名'] +'>'+数据['第一'] +'< / A> \
                < D​​IV CLASS =commentholder>'+数据['第一'] +'< / DIV>< BR /> \
                < D​​IV ID =commentactivitycontainer>< / DIV>< / DIV>< /表>< / DIV>< / DIV> \
                < D​​IV CLASS =形与GT;<形式ID =mycommentform方法=POST级=form_statusinput> \
                <输入类型=隐藏名称=streamidcontentID =streamidcontent值=+数据['comment_streamitem'] +'> \
                <输入类型=文本名称=内容ID =内容占位符=说什么自动完成=关闭> \
                <输入类型=提交ID =按钮值=频道>< /形式GT;< / DIV> \
                < D​​IV CLASS =stream_comment_holder的风格=显示:;>< D​​IV CLASS =like_name>< B> \
                < A HREF =?profile.php用户名='+数据['用户名'] +'>您像该< / A> \
                < / B>< / DIV>< / DIV>');
                  警报(成功!);
 },
 错误:函数(XHR,ajaxOptions,thrownError){
    警报(xhr.statusText);
    警报(xhr.status);
    警报(thrownError);
 }
 });
        返回false
    });
 });
 < / SCRIPT>
 

REPONSE

  INSERT INTO streamdata_comments(comment_poster,comment_streamitem,comment_datetime,comment_content)VALUES (10,4090,UTC_TIMESTAMP(),'fff'){"comment_id":"2016","comment_streamitem":"4090","username":"hazy","id":"10","first":"Lucy","middle":"","last":"Botham"}
 

PHP页面

 < PHP
在session_start();
要求包括/ rawfeeds_load.php;

如果(使用isset($ _ POST ['streamidcontent'])及使用isset($ _ POST ['内容'])){
rawfeeds_user_core :: add_comment($ _ POST ['streamidcontent'],$ _ POST ['内容']);


$ JSON =阵列();
$查询=选择COMMENT_ID,comment_datetime,comment_streamitem,comment_poster从streamdata_comments WHERE comment_poster ='。$ _ SESSION ['身份证'。'和comment_streamitem ='。$ _ POST ['streamidcontent'。'ORDER BY comment_datetime降序;
$ CHECK1 = mysqli_query($ mysqli的,$检查);
$ resultArr = mysqli_fetch_array($ CHECK1);
$ JSON ['COMMENT_ID'] = $ resultArr ['COMMENT_ID'];
$ JSON ['comment_streamitem'] = $ resultArr ['comment_streamitem'];
mysqli_free_result($ CHECK1);

$查询=SELECT * FROM用户WHERE ID =$ _ SESSION ['身份证']。;
$ CHECK1 = mysqli_query($ mysqli的,$检查);
$ resultArr = mysqli_fetch_array($ CHECK1);
$ JSON [用户名] = $ resultArr [用户名];
$ JSON ['身份证'] = $ resultArr ['身份证'];
$ JSON ['第一'] = $ resultArr ['第一'];
$ JSON ['中间'] = $ resultArr ['中间'];
$ JSON ['最后'] = $ resultArr ['最后'];
mysqli_free_result($ CHECK1);

回声json_en code($ JSON);
}
?>
 

解决方案

如上所述@thomas。我是呼应了SQL查询伸到我的功能。我删除了这一点,它现在可以正常使用。

I've been trying to find out the issue with this for days. As my data is being sent and retrieved, yet it doesn't post into my div.. Why? I did a test and found that I a SyntaxERROR unexpected character.. And can I find it.. Can I heck.

Can someone look through this and tell me of any mistakes please.

<script>
$(document).ready(function(){
    $("form#mycommentform").submit(function() {

        var streamidcontent = $(this).children("#streamidcontent").val();
        var contents = $(this).children("#contents").val();
        $.ajax({
            type: "POST",
            url: "comment_add.php",
            cache: false,
            dataType: "json",
            data: { streamidcontent: streamidcontent, contents: contents }, 
            success: function(data){  
                $("#containerid").html('<div class="stream_comment_holder" id="comment_holder_'+data['comment_streamitem']+'">\
                <div id="comment_list_'+data['comment_streamitem']+'">\
                <div id="tgy"></div><div class="stream_comment" id="comment_'+data['comment_id']+'" style="margin-top:0px;">\
                <table width=100%><tr><td valign=top width=30px></a><td valign=top align=left>\
                <a href="/profile.php?username='+data['username']+'">'+data['first']+'</a>\
                <div class="commentholder">'+data['first']+'</div><br/>\
                <div id="commentactivitycontainer"></div></div></table></div></div>\
                <div class="form"><form id="mycommentform" method="POST" class="form_statusinput">\
                <input type="hidden"  name="streamidcontent" id="streamidcontent" value="'+data['comment_streamitem']+'">\
                <input type="text" name="contents" id="contents" placeholder="Say something" autocomplete="off">\
                <input type="submit" id="button" value="Feed"></form></div>\
                <div class="stream_comment_holder" style="display:;"><div class="like_name"><b>\
                <a href="profile.php?username='+data['username']+'">You Like This</a>\
                </b></div></div>');
                  alert("SUCCESS!!!");
 },
 error: function (xhr, ajaxOptions, thrownError) {
    alert(xhr.statusText);
    alert(xhr.status);
    alert(thrownError);
 }
 });
        return false
    });
 });
 </script>

REPONSE

INSERT INTO streamdata_comments(comment_poster, comment_streamitem, comment_datetime, comment_content) VALUES (10,4090,UTC_TIMESTAMP(),'fff'){"comment_id":"2016","comment_streamitem":"4090","username":"hazy","id":"10","first":"Lucy","middle":"","last":"Botham"}

PHP PAGE

<?php
session_start();
require"include/rawfeeds_load.php";

if(isset($_POST['streamidcontent'])&isset($_POST['contents'])){
rawfeeds_user_core::add_comment($_POST['streamidcontent'],$_POST['contents']);


$json = array();
$check = "SELECT comment_id, comment_datetime, comment_streamitem, comment_poster FROM streamdata_comments WHERE comment_poster='".$_SESSION['id']."' AND comment_streamitem='".$_POST['streamidcontent']."' ORDER BY comment_datetime DESC";
$check1 = mysqli_query($mysqli,$check);
$resultArr = mysqli_fetch_array($check1);
$json['comment_id'] = $resultArr['comment_id'];
$json['comment_streamitem'] = $resultArr['comment_streamitem'];
mysqli_free_result($check1);

$check = "SELECT * FROM users WHERE id=".$_SESSION['id']."";
$check1 = mysqli_query($mysqli,$check);
$resultArr = mysqli_fetch_array($check1);
$json['username'] = $resultArr['username'];
$json['id'] = $resultArr['id'];
$json['first'] = $resultArr['first'];
$json['middle'] = $resultArr['middle'];
$json['last'] = $resultArr['last'];
mysqli_free_result($check1);

echo json_encode($json);
}
?>

解决方案

As @thomas stated above. I was echoing the SQL query out into my function. I removed this and its now working perfectly.

这篇关于AJAX语法错误:JSON.parse:意外的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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