gpt4 book ai didi

jquery - AJAX 返回带输出的 HTML 代码

转载 作者:太空狗 更新时间:2023-10-29 15:49:39 25 4
gpt4 key购买 nike

在尝试了来自 this 的一些解决方案之后以及许多其他问题我无法在我的代码中找到确切的问题。我的代码

$(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 代码。

代码有什么问题?

服务器端脚本

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 中,如下所示-

<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);
?>

关于jquery - AJAX 返回带输出的 HTML 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28826231/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com