Ajax request call failing from pageInit

I tried to initiate the Ajax request from page init. However, it is failing .
It works, if I put the entire Ajax request outside of the function without pageInit.

var app = new Framework7({
  on: {
    pageInit(page) {
      if (page.name === 'home') {
         loadNews();
      }
    }
  },});

Ajax Call:

let loadNews=()=>{
app.request.get('https://newsapi.org/v2/top-headlines?country=au&category=business&apiKey', '', function (data) {
  var articleItems = [];
  var result = JSON.parse(data);
  for (var i = 0; i < result.articles.length; i++) {
var title = result.articles[i].title;
var artUrl = result.articles[i].url;
var $title = $$("<a href=" + artUrl + '><p>' + title + "</p></a>");
$$('.news').append($title);
  }
  console.log('Successful');
}, function (error) {
  console.log(error);
});
}
1 Like

How failing? What error do you see or what is happening?

2 Likes

hi @krishna.d1982.
As the responesText says, you are missing the certificate, its some server config error. Also look at status code; --> 500 Internal Server Error
try the same request over http

app.request.get('http://newsapi.org/v2/top-headlines?country=au&category=business&apiKey',  
function (data) {
...
}

Perfect. It worked like a charm. proxy issue, I reckon. Thanks for the help