D
D
Dmitry2014-02-21 11:41:04
JavaScript
Dmitry, 2014-02-21 11:41:04

Correct use of Ajax json?

Hello!
Not particularly selenium in js, so I ask for help, and so I wrote an ajax filter that works using the select form, it turned out the following:

function showFil(str) {

$("#spanimg").show(); 

    jQuery.ajax({

      url:'url',type:'GET',dataType:'json', 
    
      success:function(data)

      {$.each(data.lines.item,function(i,item){
      
      $("#txtHint").append('');ё

    });
        }
    });

}


Everything basically works out correctly, but here's the problem with the next option select. I get additional results, i.e. the previous filtering is not cleared, but added to the existing one.
I read the documentation, as I understand it is connected with append, I tried to change it to .html, as a result, only one element is displayed.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Petrov, 2014-02-21
@muldy

success: function(data) {
  $("#txtHint").html('');
  $.each(data.lines.item,function(i,item){
    $("#txtHint").append(''); //тут же выводится элемент, а не пустое значение, я правильно понимаю?
  });
}

On success, we clear txtHint, then fill it.

A
Andrew Dabich, 2014-02-21
@dabich

The easiest way is to clear the result block. Before getting data, just clear the previous ones.$("#txtHint").html('');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question