简体   繁体   中英

replaceWith only working once

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 + "\nStatus: " + status);
    $("#searchresults").replaceWith(data);

  });
alert( "Handler for .keyup() called." );

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 + "\nStatus: " + status);
        $("#searchresults").html(data);

    });
    alert("Handler for .keyup() called.");
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM