Ja mam taki błąd:
Uncaught TypeError: Cannot call method 'getJSON' of undefined
wywołuje to z konsoli
$.getJSON( 'http://localhost/chrome/message.php', function( data ) {
$( 'div' ).html( data.var1 + ' ' + data.var2 );
ppp = data.var1;
});
wpisuje ppp i dostaje odpowiedź prawidłową.
Teraz jak uruchomoe tą funkcję
function show($) {
var notification;
var ppp = 'ppp';
var time = /(..)(:..)/.exec(new Date()); // The prettyprinted time.
var hour = time[1] % 12 || 12; // The prettyprinted hour.
var period = time[1] < 12 ? 'a.m.' : 'p.m.'; // The period of the day.
//my_window = window.open("http://localhost/chrome/index_chrome.php", "new");
//ppp = my_window.window.document.getElementById('nazwa');
$.getJSON( 'http://localhost/chrome/message.php', function( data ) {
$( 'div' ).html( data.var1 + ' ' + data.var2 );
ppp = data.var1;
});
notification = window.webkitNotifications.createNotification(
'48.png', // The image.
ppp + time[2] + ' ' + period, // The title.
'Time to make the toast.' // The body.
);
w taki sposób show($); to okienko notyfikacji sie pojawia a nie działa wczytywanie zmiennych z pliku message.php
a i plik manifest:
{
"manifest_version": 2,
"name": "IMS - Chrome Extension",
"description": "Dodatek do Google Chrome dla IMS - Spamel",
"version": "1.1",
"permissions": [
"<all_urls>", "tabs", "notifications"
],
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"options_page": "options.html",
"background": {
"scripts": ["background.js", "jquery.js"]
}
}
Inaczej ta funkcja odpalona z konsoli działa:
function show() {
var notification;
var ima = '48.png';
$.getJSON( 'http://localhost/chrome/message2.php', function( data ) {
$( 'div' ).html( data.var1 + ' ' + data.var2 );
ppp = data.var1;
ppp2 = data.var2;
});
notification = window.webkitNotifications.createNotification(
'48.png', // The image.
ppp + '', // The title.
ppp2 + '' // The body.
);
notification.show();
}
ta sama funkcja jako dodatek zwraca błąd: Uncaught ReferenceError: $ is not defined
w lini:
$.getJSON( 'http://localhost/chrome/message2.php', function( data ) {
co jest grane już mnie trafa ?