weixin_33709364 2014-12-09 01:45 采纳率: 0%
浏览 44

replaceWith只工作一次

Replace with is only working once, I am outputting the data and this is updating so I know data has changed, however it is not writing the new data to the div appart from the 1st time.

$( "#searchboxform" ).keyup(function() {
    var forminfo = $('#searchboxform').val();
     $.get("searchliveresults.php?search="+forminfo,function(data,status){
    alert("Data: " + data + "
Status: " + status);
    $("#searchresults").replaceWith(data);

  });
alert( "Handler for .keyup() called." );
  • 写回答

1条回答 默认 最新

  • weixin_33744141 2014-12-09 01:53
    关注

    replaceWith(data) is replacing the entire element when I think you want the container #searchresults to persist. Change replaceWith to html like so:

    $("#searchboxform").keyup(function () {
        var forminfo = $('#searchboxform').val();
        $.get("searchliveresults.php?search=" + forminfo, function (data, status) {
            alert("Data: " + data + "
    Status: " + status);
            $("#searchresults").html(data);
    
        });
        alert("Handler for .keyup() called.");
    });
    
    评论

报告相同问题?