Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/259.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php &引用;“输入意外结束”;使用Ajax_Php_Ajax_Arrays_Json_Row - Fatal编程技术网

Php &引用;“输入意外结束”;使用Ajax

Php &引用;“输入意外结束”;使用Ajax,php,ajax,arrays,json,row,Php,Ajax,Arrays,Json,Row,我正在构建一个线程消息传递系统。我使用AJAX将父线程id发送到检索线程的php文件(许多具有相同父线程id的消息) 在ajax中,我发送父id data:{ parent_id: $(this).data('id'), ajax: 'true' }, 我在php文件中使用这个父\u id,使用一个检索一些行的查询,并使用以下方法将它们传回: $ret_msg_query_result=mysql_query($retrive_query); while ($retrieved

我正在构建一个线程消息传递系统。我使用AJAX将父线程id发送到检索线程的php文件(许多具有相同父线程id的消息)

在ajax中,我发送父id

data:{
    parent_id: $(this).data('id'),
    ajax: 'true'
},
我在php文件中使用这个父\u id,使用一个检索一些行的查询,并使用以下方法将它们传回:

$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";    
}
然后回到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); 
                         }
                     } 
            }); 
        }); 
     });
我通过这种方式(拆分)将Stackoverflow上的帖子中的每一行转换为一个对象

该函数可以正确地检索消息的ID,甚至检索整行。但我明白了

“未捕获的语法错误:输入意外结束”

它指向console.log(obj.id)前面的行

我在StackOverflow中搜索了这个错误,它通常显示为缺少一个右括号,但我找不到任何右括号


谢谢,

此函数中缺少一个
}

success: function(data){
                var strLines = data.split("\n");
                for (var i in strLines) {
                    var obj = JSON.parse(strLines[i]);
                    console.log(obj.id);
                **}**
            }
注意:取下4x*,不应在那里:)


那应该可以解决它

我解决了这个问题。。。这是因为我正在使用“/n”进行拆分,这使得strline类似于{row},{row},{row}

结尾处的逗号导致意外的结尾。因此,我使用计数器检查行数,如果是最后一行,则不要插入“/n”


也感谢Limelights的帮助:)

当php脚本运行正常时,我忘了返回一些内容,因此得到了这个消息。我刚刚添加了如下内容:

die (json_encode (array ('reponse'=>'Your script worked fine')));

在我的php脚本的末尾,这就解决了它。您也可以使用“response”来检查它是否正常工作。

好的,谢谢limelights,但我的代码中已经有了它,很抱歉我没有粘贴所有代码,但这里是$(document)。就绪(function(){$(“.msgsRow li.msg_subject.msgsRow li.msg_content”)。单击(function(){$.ajax({type:'POST',url:ajax_url)+“front/RetrieveMsg.php”,数据:{parent_id:$(this.data('id'),ajax:'true'},success:function(data){var strLines=data.split(“\n”);for(strLines中的var i){var obj=JSON.parse(strLines[i]);console.log(obj.id);}}好的,我会用正确的代码编辑你的问题。你收到的数据是什么样子的?
die (json_encode (array ('reponse'=>'Your script worked fine')));