I am building a thread-messaging system. I used AJAX to send the parent_id to the php file which retrieved the thread (many messages with the same parent_id)
in the ajax, I send the parent_id
data:{
parent_id: $(this).data('id'),
ajax: 'true'
},
I use this parent_id in the php file using a query which retrieves some rows and I pass them back using this :
$ret_msg_query_result=mysql_query($retrive_query);
while ($retrieved_msg_fetched=mysql_fetch_assoc($ret_msg_query_result))
{
echo json_encode($retrieved_msg_fetched) . "\n";
}
and then back to Ajax:
$(document).ready(function() {
$(".msgsRow li.msg_subject,.msgsRow li.msg_content").click(function() {
$.ajax({
type: 'POST',
url: AJAX_URL+"front/RetrieveMsg.php",
data:{ parent_id: $(this).data('id'), ajax: 'true' },
success: function(data) {
var strLines = data.split("\n");
for (var i in strLines) {
var obj = JSON.parse(strLines[i]);
console.log(obj.id);
}
}
});
});
});
I got this way (of splitting) to convert each row into an object from a post here on Stackoverflow Sending/Parsing multiple JSON objects
The function works right retrieving the ids of messages and even retrieving the full row. But I get
"Uncaught SyntaxError: Unexpected end of input "
and it points to the line before console.log(obj.id);
I searched StackOverflow for this error and it usually appears for missing a closing parenthesis but I can'd find any.
Thanks,