0

I have data attribute in my HTML page. I have a JSON file "rss.json". I am not getting the typescript code to call the JSON using AJAX.

<div class="js-rssfeed" data-url="rss.json"></div> //HTML

//TypeScript Code

 class RSSFeedManager {
 "use strict";

 private rootSelectionString: string = ".js-rssfeed";


 private $rootSelector: JQuery; 
constructor() {
     var base = this;
    base.$rootSelector = $(base.rootSelectionString);
    base.rssValidate();

}
private rssValidate() {
var base=this;
  if(base.$rootSelector.length!==0) {
        //getRssFeedJson();
    }
}   
}

var _RSSFeedManager = new RSSFeedManager();
export = _RSSFeedManager;

closed as off-topic by fuxia Dec 12 '16 at 12:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

If this question can be reworded to fit the rules in the help center, please edit the question.

0

using $.getJSON Jquery function you can load JSON data from the server using a GET HTTP request.

/////
     private rssValidate() {
        var base=this;
          if(base.$rootSelector.length!==0) {

                var jsonUrl = base.$rootSelector(base.$rootSelectionString).attr('data-url'); 
                $.getJSON(jsonUrl, function(data) {
                  console.log(data);
                });
            }
        }   
        }
///////

hope this help

  • ok try now , i have edited my code – Govind Kumar Nov 23 '16 at 6:49
  • Its giving the same error!!! But I have corrected it by var jsonUrl = $(".js-rssfeed").data('url'); Thanks – Pawan Nov 23 '16 at 6:50
  • or you can do this replace it to var jsonUrl = jQuery(base.$rootSelector).attr('data-url'); – Govind Kumar Nov 23 '16 at 6:52
  • ohh thats great!!! – Pawan Nov 23 '16 at 6:59
  • Can I do the same with AJAX? – Pawan Nov 23 '16 at 7:19

Not the answer you're looking for? Browse other questions tagged or ask your own question.