P
P
Paka2017-08-24 09:25:18
JavaScript
Paka, 2017-08-24 09:25:18

JS visibility of a callback inside a callback?

I have a code (chrome extension) that i don't understand due to js specifics

chrome.runtime.onMessage.addListener(
  function(message, sender, sendResponse)
  {
    $.ajax({
      url: "http://some.site"
      ,type: "POST"
      ,data: message
      ,success: function(data)
      {
        sendResponse('что-то не работает');
      }
    });
    
    sendResponse('работает');
  }
);


Why is sendResponse('something not working'); does not work? I suspect that I am trying to call sendResponse in the wrong context.
How should this code be read correctly?
And how to achieve that the success callback from Ajax could call sendResponse?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question