Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
jqueryajaxhtml(newhtml)输出奇怪的html_Jquery_Html_Ajax - Fatal编程技术网

jqueryajaxhtml(newhtml)输出奇怪的html

jqueryajaxhtml(newhtml)输出奇怪的html,jquery,html,ajax,Jquery,Html,Ajax,我有一个jQueryAjax函数,可以从PHP脚本中获取新的HTML。PHP脚本工作正常,并将正确的HTML发送回jQuery,但是,当我使用该函数时,输出的HTML是不正确的。我已将HTML放入中,以查看返回的代码是否正确,而且确实正确。但当我试图将其输出到HTML中时,它就像“已损坏” 以下是jQuery函数: $(function() { $(".form-control").keyup(function() { var searchString = $(this)

我有一个jQueryAjax函数,可以从PHP脚本中获取新的HTML。PHP脚本工作正常,并将正确的HTML发送回jQuery,但是,当我使用该函数时,输出的HTML是不正确的。我已将HTML放入
中,以查看返回的代码是否正确,而且确实正确。但当我试图将其输出到HTML中时,它就像“已损坏”

以下是jQuery函数:

$(function() {
    $(".form-control").keyup(function() {
        var searchString = $(this).val();
        var dataString = 'search=' + searchString;
        if(searchString != '') {
            $.ajax({
                type: "POST",
                url: "core/handle.php",
                data: dataString,
                cache:false,
                success: function(html) {
                    var start = '<div class="row"><h2>' + searchString + '</h2>';
                    var end = '</div>';
                    html = start + html + end;
                    $("#books-wrapper").html(html);
                }
            });
        }
        return false;
    });
});
$(函数(){
$(“.form控件”).keyup(函数(){
var searchString=$(this.val();
var dataString='search='+searchString;
如果(搜索字符串!=''){
$.ajax({
类型:“POST”,
url:“core/handle.php”,
数据:dataString,
cache:false,
成功:函数(html){
var start=''+searchString+'';
var-end='';
html=开始+html+结束;
$(“#书籍包装”).html(html);
}
});
}
返回false;
});
});
以下是将jQuery的html()函数用于
时的输出:


下面是实际的源代码输出:

<div id="books-wrapper">
    <div class="row">
        <h2>b</h2>
           <div class="col-lg-3>
                <a href=" index.php?id="1&quot;">
                <img src="img/books/book_1.jpg" alt="Book one">
           </div>
           <div class="col-lg-3>
                <a href=" index.php?id="2&quot;">
                <img src="img/books/book_2.jpg" alt="Book two">
           </div>
    </div>
</div>

B

您错过了class=“col-lg-3^^^^中的结束引号,请检查是否存在类似错误,并使用

改变


我认为,您应该执行
html=start+html.prop('outerHTML')+end
因为“html”(变量)是jQuery的DOM对象,而不是字符串。


<a href=" index.php?id="1&quot;">
应该是

<a href=' index.php?id="1&quot;"'>

哦,你说得对!这解决了我的问题。非常感谢!
<div class="col-lg-3">
<a href=" index.php?id="1&quot;">
<a href=' index.php?id="1&quot;"'>