How to display a specific tag in a file, such as a description in a list, dynamically using jquery?

I am trying to get some data from a file, for example some.txt. I want to display some data in this file, as a description below each list in the list.

$(xml).find('section[order="' + order + '"] content').each(function () { var content = $(this).text(); var seq = order + '' + $(this).attr('order'); var file = $(this).attr('file'); $("#content").append('<li><a href="#" data-sequence="s' + seq + '" file="' + file + '">' + content + ' </a> </li> '); }); $("#content").listview('refresh'); }); 

In the above code, I created a listview. Now I have changed the code as shown below:

 $("#content_list").append('<li><a href="#" file="' + file +'">' + content + ' </a><p class="description text"></p> </li> '); $(".description").each(function() { $(".text").load(file, function() { var txt = $(this).find('I').text(); $("#content_list").append('<p>' + txt + '</p>'); }); }); 

In the above code, the "file" attribute contains some .txt file. Using this file, I want to get some data to display the text as a description for the title in the list. I tried in many ways, but the whole file is displayed.

Thanks at Advance.

+1
source share
1 answer

You started your .ready code, which is not recommended for use with jQuery Mobile ( explanation ). I replaced it with pageinit , which is equivalent to .ready but is designed to work with jQuery Mobile.

. load not used properly; you had to read the extracted (data) from the downloaded file in this way.

 $('#files').load(file, function (data) { var txt = $(data).find('i').text(); ....... }); 

Here is the new code .

+2
source

Source: https://habr.com/ru/post/1499026/


All Articles