JQuery/Javascript how to Parse HTML using a Get

后端 未结 2 778
南旧
南旧 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.

    0 讨论(0)
  • 2021-01-28 08:35

    Well for the first point you could just run

    $('#shares').on('change', function(){
        var val = $(this).val();
        //submit another ajax request with this value, and get the relevant page, then you'd just need to parse it for the appropriate content from that page.
    });
    

    If you want to parse the returned page and get only part of this we'd need to know the markup structure.

    0 讨论(0)
提交回复
热议问题