Chrome Extension: $.ajax is not a function
I've built a chrome extension that will rely upon ajax calls from the background script, but for some reason the ajax function is not registered as a function at the time I make my call. I thought first that it was a problem in my manifest, but realized that it would be throwing an error about $
being undefined if jquery wasn't being injected for use. I'm wondering now if it might be some sort of securities issue? I would think that if that was the case, though, that the function would still execute, but throw an error when the transport to say an illegal URL occurred. I'm really at a loss here.
Before trying $.ajax()
I was using $.getScript()
, but it throws the similar error that getScript is not a function.
In my manifest.json, I have this:
"background": {
"scripts": ["vendor/jquery.js", "background.js"]
},
And this is in my background.js:
chrome.runtime.onInstalled.addListener(function(){
...
var Core = {
...
load: function(name){
var src = EXTERNAL+name+".js";
$.ajax({
url: src,
type: "script",
success: function(result) {
console.log(result);
}
});
},
};
function initialize(){
...
Core.load(name);
}
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
var request = message.data;
var type = request.type;
switch(type){
case 'popup_handshake':
sendResponse({data:{domain: domain, seed: seed}});
break;
case 'seed':
domain = request.domain;
uW = request.uW;
seed = uW.seed;
cm = uW.cm;
delete uW.seed;
delete uW.cm;
initialize();
break;
}
});
});
What could the problem possibly be?
jquery google-chrome-extension
|
show 1 more comment
I've built a chrome extension that will rely upon ajax calls from the background script, but for some reason the ajax function is not registered as a function at the time I make my call. I thought first that it was a problem in my manifest, but realized that it would be throwing an error about $
being undefined if jquery wasn't being injected for use. I'm wondering now if it might be some sort of securities issue? I would think that if that was the case, though, that the function would still execute, but throw an error when the transport to say an illegal URL occurred. I'm really at a loss here.
Before trying $.ajax()
I was using $.getScript()
, but it throws the similar error that getScript is not a function.
In my manifest.json, I have this:
"background": {
"scripts": ["vendor/jquery.js", "background.js"]
},
And this is in my background.js:
chrome.runtime.onInstalled.addListener(function(){
...
var Core = {
...
load: function(name){
var src = EXTERNAL+name+".js";
$.ajax({
url: src,
type: "script",
success: function(result) {
console.log(result);
}
});
},
};
function initialize(){
...
Core.load(name);
}
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
var request = message.data;
var type = request.type;
switch(type){
case 'popup_handshake':
sendResponse({data:{domain: domain, seed: seed}});
break;
case 'seed':
domain = request.domain;
uW = request.uW;
seed = uW.seed;
cm = uW.cm;
delete uW.seed;
delete uW.cm;
initialize();
break;
}
});
});
What could the problem possibly be?
jquery google-chrome-extension
Are you loading JQuery? Possibly a race condition?
– Action Coding
Nov 11 '18 at 22:14
I was under the impression that the order in which the scripts are defined in manifest.json determined load order. I can view the generated background_page.html and the scripts are included correctly.
– chaoskreator
Nov 12 '18 at 0:28
A common mistake is to include background.js in other places/pages like in content_scripts and see an error in the web page console. If that's not the case and the error is shown in the real background page console, it looks like a buggy jquery.js.
– wOxxOm
Nov 12 '18 at 6:40
@wOxxOm yeah, I've got it running on the background page, and not injected via content_scripts. I'll see if another copy of jquery will work, even though I just downloaded this one from the CDN.
– chaoskreator
Nov 12 '18 at 18:13
Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
– Xan
Nov 14 '18 at 14:57
|
show 1 more comment
I've built a chrome extension that will rely upon ajax calls from the background script, but for some reason the ajax function is not registered as a function at the time I make my call. I thought first that it was a problem in my manifest, but realized that it would be throwing an error about $
being undefined if jquery wasn't being injected for use. I'm wondering now if it might be some sort of securities issue? I would think that if that was the case, though, that the function would still execute, but throw an error when the transport to say an illegal URL occurred. I'm really at a loss here.
Before trying $.ajax()
I was using $.getScript()
, but it throws the similar error that getScript is not a function.
In my manifest.json, I have this:
"background": {
"scripts": ["vendor/jquery.js", "background.js"]
},
And this is in my background.js:
chrome.runtime.onInstalled.addListener(function(){
...
var Core = {
...
load: function(name){
var src = EXTERNAL+name+".js";
$.ajax({
url: src,
type: "script",
success: function(result) {
console.log(result);
}
});
},
};
function initialize(){
...
Core.load(name);
}
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
var request = message.data;
var type = request.type;
switch(type){
case 'popup_handshake':
sendResponse({data:{domain: domain, seed: seed}});
break;
case 'seed':
domain = request.domain;
uW = request.uW;
seed = uW.seed;
cm = uW.cm;
delete uW.seed;
delete uW.cm;
initialize();
break;
}
});
});
What could the problem possibly be?
jquery google-chrome-extension
I've built a chrome extension that will rely upon ajax calls from the background script, but for some reason the ajax function is not registered as a function at the time I make my call. I thought first that it was a problem in my manifest, but realized that it would be throwing an error about $
being undefined if jquery wasn't being injected for use. I'm wondering now if it might be some sort of securities issue? I would think that if that was the case, though, that the function would still execute, but throw an error when the transport to say an illegal URL occurred. I'm really at a loss here.
Before trying $.ajax()
I was using $.getScript()
, but it throws the similar error that getScript is not a function.
In my manifest.json, I have this:
"background": {
"scripts": ["vendor/jquery.js", "background.js"]
},
And this is in my background.js:
chrome.runtime.onInstalled.addListener(function(){
...
var Core = {
...
load: function(name){
var src = EXTERNAL+name+".js";
$.ajax({
url: src,
type: "script",
success: function(result) {
console.log(result);
}
});
},
};
function initialize(){
...
Core.load(name);
}
chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){
var request = message.data;
var type = request.type;
switch(type){
case 'popup_handshake':
sendResponse({data:{domain: domain, seed: seed}});
break;
case 'seed':
domain = request.domain;
uW = request.uW;
seed = uW.seed;
cm = uW.cm;
delete uW.seed;
delete uW.cm;
initialize();
break;
}
});
});
What could the problem possibly be?
jquery google-chrome-extension
jquery google-chrome-extension
asked Nov 11 '18 at 20:00
chaoskreatorchaoskreator
46411032
46411032
Are you loading JQuery? Possibly a race condition?
– Action Coding
Nov 11 '18 at 22:14
I was under the impression that the order in which the scripts are defined in manifest.json determined load order. I can view the generated background_page.html and the scripts are included correctly.
– chaoskreator
Nov 12 '18 at 0:28
A common mistake is to include background.js in other places/pages like in content_scripts and see an error in the web page console. If that's not the case and the error is shown in the real background page console, it looks like a buggy jquery.js.
– wOxxOm
Nov 12 '18 at 6:40
@wOxxOm yeah, I've got it running on the background page, and not injected via content_scripts. I'll see if another copy of jquery will work, even though I just downloaded this one from the CDN.
– chaoskreator
Nov 12 '18 at 18:13
Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
– Xan
Nov 14 '18 at 14:57
|
show 1 more comment
Are you loading JQuery? Possibly a race condition?
– Action Coding
Nov 11 '18 at 22:14
I was under the impression that the order in which the scripts are defined in manifest.json determined load order. I can view the generated background_page.html and the scripts are included correctly.
– chaoskreator
Nov 12 '18 at 0:28
A common mistake is to include background.js in other places/pages like in content_scripts and see an error in the web page console. If that's not the case and the error is shown in the real background page console, it looks like a buggy jquery.js.
– wOxxOm
Nov 12 '18 at 6:40
@wOxxOm yeah, I've got it running on the background page, and not injected via content_scripts. I'll see if another copy of jquery will work, even though I just downloaded this one from the CDN.
– chaoskreator
Nov 12 '18 at 18:13
Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
– Xan
Nov 14 '18 at 14:57
Are you loading JQuery? Possibly a race condition?
– Action Coding
Nov 11 '18 at 22:14
Are you loading JQuery? Possibly a race condition?
– Action Coding
Nov 11 '18 at 22:14
I was under the impression that the order in which the scripts are defined in manifest.json determined load order. I can view the generated background_page.html and the scripts are included correctly.
– chaoskreator
Nov 12 '18 at 0:28
I was under the impression that the order in which the scripts are defined in manifest.json determined load order. I can view the generated background_page.html and the scripts are included correctly.
– chaoskreator
Nov 12 '18 at 0:28
A common mistake is to include background.js in other places/pages like in content_scripts and see an error in the web page console. If that's not the case and the error is shown in the real background page console, it looks like a buggy jquery.js.
– wOxxOm
Nov 12 '18 at 6:40
A common mistake is to include background.js in other places/pages like in content_scripts and see an error in the web page console. If that's not the case and the error is shown in the real background page console, it looks like a buggy jquery.js.
– wOxxOm
Nov 12 '18 at 6:40
@wOxxOm yeah, I've got it running on the background page, and not injected via content_scripts. I'll see if another copy of jquery will work, even though I just downloaded this one from the CDN.
– chaoskreator
Nov 12 '18 at 18:13
@wOxxOm yeah, I've got it running on the background page, and not injected via content_scripts. I'll see if another copy of jquery will work, even though I just downloaded this one from the CDN.
– chaoskreator
Nov 12 '18 at 18:13
Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
– Xan
Nov 14 '18 at 14:57
Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
– Xan
Nov 14 '18 at 14:57
|
show 1 more comment
1 Answer
1
active
oldest
votes
[Edit][Tested]
I just add:
"background": {
"scripts": ["jquery.js","background.js"]
},
I called $.ajax on my background.js, and it looks fine, it returns:
ƒ (t,n){"object"==typeof t&&(n=t,t=void 0),n=n||{};var i,o,a,s,u,l,c,f,p,d,h=w.ajaxSetup({},n),g=h.context||h,y=h.context&&(g.nodeType||g.jquery)?w(g):w.event,v=w.Deferred(),m=w.Callbacks("once memory"…
Take a look on your jquery.js script....
I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
– Demian
Nov 12 '18 at 16:10
I just downloaded this jquery.js from the CDN, but I'll download a fresh copy and see if that helps.
– chaoskreator
Nov 12 '18 at 18:15
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252676%2fchrome-extension-ajax-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
[Edit][Tested]
I just add:
"background": {
"scripts": ["jquery.js","background.js"]
},
I called $.ajax on my background.js, and it looks fine, it returns:
ƒ (t,n){"object"==typeof t&&(n=t,t=void 0),n=n||{};var i,o,a,s,u,l,c,f,p,d,h=w.ajaxSetup({},n),g=h.context||h,y=h.context&&(g.nodeType||g.jquery)?w(g):w.event,v=w.Deferred(),m=w.Callbacks("once memory"…
Take a look on your jquery.js script....
I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
– Demian
Nov 12 '18 at 16:10
I just downloaded this jquery.js from the CDN, but I'll download a fresh copy and see if that helps.
– chaoskreator
Nov 12 '18 at 18:15
add a comment |
[Edit][Tested]
I just add:
"background": {
"scripts": ["jquery.js","background.js"]
},
I called $.ajax on my background.js, and it looks fine, it returns:
ƒ (t,n){"object"==typeof t&&(n=t,t=void 0),n=n||{};var i,o,a,s,u,l,c,f,p,d,h=w.ajaxSetup({},n),g=h.context||h,y=h.context&&(g.nodeType||g.jquery)?w(g):w.event,v=w.Deferred(),m=w.Callbacks("once memory"…
Take a look on your jquery.js script....
I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
– Demian
Nov 12 '18 at 16:10
I just downloaded this jquery.js from the CDN, but I'll download a fresh copy and see if that helps.
– chaoskreator
Nov 12 '18 at 18:15
add a comment |
[Edit][Tested]
I just add:
"background": {
"scripts": ["jquery.js","background.js"]
},
I called $.ajax on my background.js, and it looks fine, it returns:
ƒ (t,n){"object"==typeof t&&(n=t,t=void 0),n=n||{};var i,o,a,s,u,l,c,f,p,d,h=w.ajaxSetup({},n),g=h.context||h,y=h.context&&(g.nodeType||g.jquery)?w(g):w.event,v=w.Deferred(),m=w.Callbacks("once memory"…
Take a look on your jquery.js script....
[Edit][Tested]
I just add:
"background": {
"scripts": ["jquery.js","background.js"]
},
I called $.ajax on my background.js, and it looks fine, it returns:
ƒ (t,n){"object"==typeof t&&(n=t,t=void 0),n=n||{};var i,o,a,s,u,l,c,f,p,d,h=w.ajaxSetup({},n),g=h.context||h,y=h.context&&(g.nodeType||g.jquery)?w(g):w.event,v=w.Deferred(),m=w.Callbacks("once memory"…
Take a look on your jquery.js script....
edited Nov 12 '18 at 16:09
answered Nov 12 '18 at 14:36
DemianDemian
1637
1637
I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
– Demian
Nov 12 '18 at 16:10
I just downloaded this jquery.js from the CDN, but I'll download a fresh copy and see if that helps.
– chaoskreator
Nov 12 '18 at 18:15
add a comment |
I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
– Demian
Nov 12 '18 at 16:10
I just downloaded this jquery.js from the CDN, but I'll download a fresh copy and see if that helps.
– chaoskreator
Nov 12 '18 at 18:15
I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
– Demian
Nov 12 '18 at 16:10
I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
– Demian
Nov 12 '18 at 16:10
I just downloaded this jquery.js from the CDN, but I'll download a fresh copy and see if that helps.
– chaoskreator
Nov 12 '18 at 18:15
I just downloaded this jquery.js from the CDN, but I'll download a fresh copy and see if that helps.
– chaoskreator
Nov 12 '18 at 18:15
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53252676%2fchrome-extension-ajax-is-not-a-function%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Are you loading JQuery? Possibly a race condition?
– Action Coding
Nov 11 '18 at 22:14
I was under the impression that the order in which the scripts are defined in manifest.json determined load order. I can view the generated background_page.html and the scripts are included correctly.
– chaoskreator
Nov 12 '18 at 0:28
A common mistake is to include background.js in other places/pages like in content_scripts and see an error in the web page console. If that's not the case and the error is shown in the real background page console, it looks like a buggy jquery.js.
– wOxxOm
Nov 12 '18 at 6:40
@wOxxOm yeah, I've got it running on the background page, and not injected via content_scripts. I'll see if another copy of jquery will work, even though I just downloaded this one from the CDN.
– chaoskreator
Nov 12 '18 at 18:13
Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
– Xan
Nov 14 '18 at 14:57