[英]AJAX SyntaxError: JSON.parse: unexpected character
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?
在发送和检索我的数据时,它没有发布到我的div中。为什么? I did a test and found that I a SyntaxERROR unexpected character.. And can I find it.. Can I heck.
我进行了测试,发现我出现了SyntaxERROR意外字符。并且可以找到它。
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页面
<?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. 正如上面的@thomas。 I was echoing the SQL query out into my function.
我正在将SQL查询回显到我的函数中。 I removed this and its now working perfectly.
我删除了它,现在可以正常工作了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.