JQuery/Javascript how to Parse HTML using a Get

后端 未结 2 779
南旧
南旧 2021-01-28 08:07

I have the following working code. This displays a drop down and also fetches a html file to be displayed:

   $.getJSON(\'json/shares.json\', function(data) {
          


        
2条回答
  •  孤独总比滥情好
    2021-01-28 08:27

    Seems like you just need to bind to the .change event of the dropdown you are creating to do the submission, which you can retrieve with .get. You can use jQuery to parse the html. It does a nice job of that:

    .appendTo('#shares')
    .change(function () {
       $.get($(this).val() + '_shares.html)
          .done(function (html) {
             var $table = $(html).find("table tr:first td").slice(0,5);
          })
          .fail(function () { /* no such file */ });
    });
    

    This code is untested, but hopefully you can follow the example. Also beware of GET caching.

提交回复
热议问题