且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

使用 jQuery ajax 响应 html 更新 div

更新时间:2023-02-11 18:24:26

您正在设置 #showresults 的任何 data 的 html,然后将其替换为自身,这没有多大意义?
我猜你在哪里真的试图在返回的数据中找到 #showresults,然后用来自 ajax 的 html 更新 DOM 中的 #showresults 元素调用:

You are setting the html of #showresults of whatever data is, and then replacing it with itself, which doesn't make much sense ?
I'm guessing you where really trying to find #showresults in the returned data, and then update the #showresults element in the DOM with the html from the one from the ajax call :

$('#submitform').click(function () {
    $.ajax({
        url: "getinfo.asp",
        data: {
            txtsearch: $('#appendedInputButton').val()
        },
        type: "GET",
        dataType: "html",
        success: function (data) {
            var result = $('<div />').append(data).find('#showresults').html();
            $('#showresults').html(result);
        },
        error: function (xhr, status) {
            alert("Sorry, there was a problem!");
        },
        complete: function (xhr, status) {
            //$('#showresults').slideDown('slow')
        }
    });
});