How to show callback?

Asked

Viewed 83 times

0

I have this Javascript and would like to take this callback from another page with Javascript how can I do that? Ex: this callbck is on a server with the name "callb" and I have an HTML page that is on the server and I want to take this "callb" file and put in the HTML page.

json.prototype.resgatarValores = function(callback) { // aqui dás a callback como argumento
  $('#resultado').html('Carregando dados...');

  // Estrutura de resultado.
  $.getJSON('/webpro/webadm/lncidjson', function(data) {
    var valore = data.usuarios.map(function(u) {
      return u.valor;
    });
    var label = data.usuarios.map(function(u) {
      return u.descr;
    });
    // aqui usas a callback, passando o "valor" quando ele tiver chegado do servidor
    callback(valore, label);

  });
}

obj.resgatarValores(function(data, labels) {
  // aqui podes fazer algo com a variável (tipo array) "data" e "lavels" que terá o valor de "valore" e "label" dentro da chamada ajax.
  // Esta callback é corrida quando o ajax/getJSON tiver recebido resposta do servidor
});

  • If you open the page /webpro/webadm/lncidjson what gives you? what language do you have on the server side?

  • @Earendul I don’t have many details about it ! Plus what I do know is that this file is picking up data from a system file on the server

  • I think the comment was for @Sergio

  • @Sergio I don’t have many details about it ! Plus what I do know is that this file is picking up data from a system file on the server

  • If you open the page/url /webpro/webadm/lncidjson in the browser what gives you?

  • @Sergio I am not allowed to enter the page folder.

  • @Here’s how I can get this callback in another javascript file?

  • @nardo_warlock details are missing before I can answer you. You are trying to fetch data from an address /webpro/webadm/lncidjson but the address seems not to allow? Does this date variable inside getJSON come empty? If you do $.getJSON('/webpro/webadm/lncidjson', function(data) { console.log(data);}); what’s on your console? You know how to use the console?

  • @Sergio appears to me { "usuarios": [ { "value": 2.51, "descr": "14/02/2015", }, { "value": 2.56, "descr": "15/02/2015", }, { "value": 2.87, "descr": "16/02/2015", }, { "value": 2.89, "descr": "17/02/2015", }, { "value": 2.94, "descr": "18/02/2015", }, { } ] }, I opened the lncidjson file and it showed these.

  • With pegar o callback de outra página you refer to pegar os dados de outra página?

  • @Oeslei so as I have this callback in this javascript I wanted to take from an html page have how? Something like var takes = callback(valore, label);

  • You want to run as callback a function that is in another file, that’s it?

  • I understood the following as the calbck is with the values 'value' and 'label' I want to show these values! has how to do this?

  • http://templecoding.com/blog/2012/12/05/funes-de-callback-no-javascript/

Show 9 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.