无法使用jquery从db获取数据

时间:2017-06-15 08:11:40

标签: php jquery twitter-bootstrap laravel ckeditor

我在点击时从db检索数据时遇到问题,并将该数据放入bootstrap模式进行编辑。它的工作地点我在db中有字符串但是当数组或我有html内容的字段时它无法加载。

这是代码

    foreach ($unit_contents as $unit_content) {
         $default = $unit_content->is_default == 1 ? '(Default)' : '';
        $unit_content_html = $unit_content->content_html;

       <div style="height:40px;"><div class="block-options pull-right">
         <a href="#unit-of-content" data-toggle="modal" onclick="EditBlock('{{$unit_content->id}}', 
'{{$unit_content->label}}', 
'{{$unit_content_html}}')" data-toggle="tooltip" title="Edit" class="btn btn-xs btn-default"><i class="fa fa-pencil"></i>
        </a></div>
     {{$unit_content->label}} {{$default}}
     </div>;
        }

Jquery的

function EditBlock(id, label, unit_content_html)
    {
        alert(unit_content_html);
        $('#label').val(label);
        $('#content_html').val(unit_content_html);
    }

我使用alert测试它没有为unit_content_html提供数据,而我在db中有数据而且它是

Coulmn数据

<html>
<head>
    <title></title>
</head>
<body></body>
</html>

我想在CKEDITOR中加载这些数据;

控制台上的错误为

  

未捕获的SyntaxError:无效或意外的令牌

如果我将列数据更改为字符串,则会在警报中提供数据,但不会在CKEditor中推送该数据。

请帮助解决谢谢

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码。并以json格式从服务器端获取数据 function EditBlock(id) { $.ajax({ url: "/path/to/file?id=" + id, type: "GET", dataType: "JSON", success: function (response) { $('#label').val(response.label); CKEDITOR.instances.editor1.setData(response.html_content); }, }); }