0
$valueArr=htmlspecialchars(json_encode($event), ENT_QUOTES, 'UTF-8');

json_encode($valueArr)

<a href="javascript:void(0)"  id="event_<?=$event->event_id?>"  onclick='getDetailsEvent(<?php echo $valueArr;?>)' >

到这个函数

 <script>
    function getDetailsEvent(eObj){
        var edStr=JSON.stringify(eObj);
        m.ajax({
            type: "POST",
            url: "<?php echo SITEPATH;?>/socialuser/event_calender/gethtml.php",
            data: "ed="+edStr+"&t=<?=time()?>",
            contentType: 'application/json; charset=utf-8',
            dataType: "json",
            error: function(jqXHR, exception){
                if (jqXHR.status === 0){
                    alert('Not connect.\n Verify Network.');
                }else if (jqXHR.status == 404){
                    alert('Requested page not found. [404]');
                }else if (jqXHR.status == 500){
                    alert('Internal Server Error [500].');
                }else if (exception === 'parsererror'){
                    alert('Requested JSON parse failed.');
                }else if (exception === 'timeout'){
                    alert('Time out error.');
                }else if (exception === 'abort'){
                    alert('Ajax request aborted.');
                }else{
                    alert('Uncaught Error.\n' + jqXHR.responseText);
                }
            },
            beforeSend:function(){
                var bSend = 'l o a d i n g . . . ';
                m('#load').show();
                m('#load').html(bSend);
            },
            success: function(response){
                m('#evenDetails').html(response);
            }
        });
    }
</script>

现在在这个功能上,一切都可以正常工作,如果我没有在本地服务器中使用“数据类型:”json“”,但在服务器上这不起作用..

它会给出错误

else if (exception === 'parsererror'){
                        alert('Requested JSON parse failed.');

在ajax调用..

在打印帖子数据的帖子页面上,数据是这样的

{\"first_name\":\"Pradeep\",\"last_name\":\"Kumar\",\"profile_image\":\"thumbnail_10000022_1359466283.jpg\",\"category\":\"Restaurant\",\"category_image\":\"icon_restaurants.png\",\"category_icons\":\"restaurants_icon.png\",\"event_id\":\"17\",\"social_users_id\":\"10000022\",\"location\":\"new, Thandla, Madhya Pradesh 457777, India\",\"lat\":\"23.0048561\",\"lng\":\"74.57584440000005\",\"title\":\"dasdasd\",\"event\":\"Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry\'s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop p\",\"pic_event\":\"517a1d4a38d411366957386.jpg\",\"event_type\":\"1\",\"day\":\"15\",\"month\":\"5\",\"year\":\"2013\",\"date\":\"1368556200\",\"time\":\"0\"}

我的问题是,如果我得到这种类型的数据,我该如何 json_decode,因为它包含不会解析服务器上的数据的“\”。

4

1 回答 1

1

htmlspecialchars 函数添加特殊字符以避免安全漏洞,其中一个字符是'/' 字符。我建议只使用json_encode($event)

于 2013-05-01T14:35:47.333 回答