AJAX返回带有输出的HTML代码 [英] AJAX returns HTML code with output

查看:100
本文介绍了AJAX返回带有输出的HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尝试了和其他许多问题,我无法在我的代码中得到确切的问题.我的代码

After trying some solutions from this and many other questions I wasn't able to get what is exact problem in my code. My code

$(document).ready(function() {
    $("#botname").blur(function() {
        $.ajax({
            type: "POST",
            url: "/tukaiexotic/rq/requisition/typhead",
            contentType: "application/json; charset=utf-8",
            success: function(result) {
                $("#commmonname").val(result);
            }
        });
    });
});

它返回我的预期结果,但结果是,它返回整个页面的HTML代码.

It returns my expected result, but with result, it returns the HTML code of the whole page.

代码有什么问题?

服务器端脚本

function typhead_mod()
        {

             $this->db->select("fa_id,fa_code,fa_name");
            $aaa=$this->db->get('tukai_farms')->result();

            echo strip_tags($aaa);

        }

推荐答案

从服务器文件发送数据时使用strip_tags(如果它在php中,如下所示)-

use strip_tags while sending data from server file if that is in php like below-

<script src="jquery.js" type="text/javascript"></script>
<script>
$(document).ready(function() {
        $.ajax({
            type: "POST",
            url: "test2.php",
            contentType: "application/json; charset=utf-8",
            success: function(result) {
                //alert(result);
                $("#commmonname").html(result);
            }
        });
    });
</script>

<div id="commmonname"></div>

服务器文件

<?php
$msg="<h2>HI</h2>";
echo strip_tags($msg);
?>

这篇关于AJAX返回带有输出的HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆