복붙노트

[JQUERY] jQuery를 아약스 응답 업데이트 DIV HTML

JQUERY

jQuery를 아약스 응답 업데이트 DIV HTML

해결법


  1. 1.당신은 데이터가 무엇이든 #showresults의 HTML을 설정하고 많은 이해가되지 않는, 그 자체로 교체된다? 나는 반환 된 데이터에 #showresults을 찾기 위해 노력하고 어디에 정말 당신을 추측하고 아약스 호출의 일에서 HTML과 DOM에 #showresults 요소를 업데이트하고 있습니다 :

    당신은 데이터가 무엇이든 #showresults의 HTML을 설정하고 많은 이해가되지 않는, 그 자체로 교체된다? 나는 반환 된 데이터에 #showresults을 찾기 위해 노력하고 어디에 정말 당신을 추측하고 아약스 호출의 일에서 HTML과 DOM에 #showresults 요소를 업데이트하고 있습니다 :

    $('#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')
            }
        });
    });
    

  2. 2.거의 오년 후, 나는 조금 줄일 수 있습니다 내 대답은 많은 사람들의 노력을 비트 생각합니다.

    거의 오년 후, 나는 조금 줄일 수 있습니다 내 대답은 많은 사람들의 노력을 비트 생각합니다.

    아약스 호출의 하나의 HTML과 DOM의 요소를 업데이트하는 방법이 있음을 달성 할 수있다

    $('#submitform').click(function() {
         $.ajax({
         url: "getinfo.asp",
         data: {
             txtsearch: $('#appendedInputButton').val()
         },
         type: "GET",
         dataType : "html",
         success: function (data){
             $('#showresults').html($('#showresults',data).html());
             // similar to $(data).find('#showresults')
         },
    });
    

    또는 replaceWith와 ()

    // codes
    
    success: function (data){
       $('#showresults').replaceWith($('#showresults',data));
    },
    

  3. 3.그것은 jQuery의 .load를 사용하는 것도 가능하다 ()

    그것은 jQuery의 .load를 사용하는 것도 가능하다 ()

    $('#submitform').click(function() {
      $('#showresults').load('getinfo.asp #showresults', {
        txtsearch: $('#appendedInputButton').val()
      }, function() {
        // alert('Load was performed.')
        // $('#showresults').slideDown('slow')
      });
    });
    
    $( "#result" ).load( "ajax/test.html #container" );
    
  4. from https://stackoverflow.com/questions/18064666/update-div-with-jquery-ajax-response-html by cc-by-sa and MIT license