I am writing a chrome extension but the sendResponse
method does not work.
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if(!request.method){
return false;
}
if(request.method=='postList' && request.post_list){
// alert(1);
a_facebook_api.getPostFromDB(request.post_list, function(data){
alert(data);
sendResponse(data);
});
} else if(request.method=='postAdd' && request.post_data){
a_facebook_api.addPostToDB(request.post_data, function(data){
sendResponse(data);
});
}
return true;
}
);
chrome.runtime.sendMessage({method: "postList",post_list: post_list}, function(response) {
alert(response);
});
the function alert(data)
works. It gives me proper data with JSON format. However, the alert(response)
does not show any message. Can anyone give me some ideas why it isn't working?
Thank you in advance!