【问题标题】:how to pass html in json data to from controller to view in codeigniter如何将json数据中的html传递给控制器​​以在codeigniter中查看
【发布时间】:2017-02-07 12:41:28
【问题描述】:

我想在 json 数据中传递 html。在检索视图中的数据时,html 代码也被打印为字符串。如何在 json 消息中显示 url。

控制器代码:

                    $jsarr['msg'] = 'you have not yet - register here <a href="member/register">Register</a>';
                    $jsarr['redirect'] = 0;
                    echo json_encode($jsarr);
             }

Ajax 成功:

   if(data.result == 'success'){
         //some code
   }else{
        $(".error").text(data.msg);
   }

找到解决方案: 在 jquery 中,我使用 html 而不是文本

 if(data.result == 'success'){
     //some code
 }else{
    $(".error").html(data.msg);
}

【问题讨论】:

  • jQuery.parseHTML() 可以使用。您可以将 html 字符串传递给函数。

标签: php json codeigniter


【解决方案1】:

可能它可以像 控制器:

$html='<html>
       <head>
       </head>
      <body>
      <h1>Hello World!</h1>
      </body>
     </html>';
echo json_encode($html);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-02
    • 1970-01-01
    • 2012-12-22
    相关资源
    最近更新 更多