Chrome Extension: $.ajax is not a function









up vote
0
down vote

favorite












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?










share|improve this question





















  • Are you loading JQuery? Possibly a race condition?
    – Action Coding
    Nov 11 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 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 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 at 18:13










  • Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
    – Xan
    Nov 14 at 14:57














up vote
0
down vote

favorite












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?










share|improve this question





















  • Are you loading JQuery? Possibly a race condition?
    – Action Coding
    Nov 11 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 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 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 at 18:13










  • Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
    – Xan
    Nov 14 at 14:57












up vote
0
down vote

favorite









up vote
0
down vote

favorite











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?










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 11 at 20:00









chaoskreator

45911032




45911032











  • Are you loading JQuery? Possibly a race condition?
    – Action Coding
    Nov 11 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 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 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 at 18:13










  • Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
    – Xan
    Nov 14 at 14:57
















  • Are you loading JQuery? Possibly a race condition?
    – Action Coding
    Nov 11 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 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 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 at 18:13










  • Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
    – Xan
    Nov 14 at 14:57















Are you loading JQuery? Possibly a race condition?
– Action Coding
Nov 11 at 22:14





Are you loading JQuery? Possibly a race condition?
– Action Coding
Nov 11 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 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 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 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 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 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 at 18:13












Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
– Xan
Nov 14 at 14:57




Are you by any chance using the jQuery Slim version? It lacks AJAX-related functionality among other things.
– Xan
Nov 14 at 14:57












1 Answer
1






active

oldest

votes

















up vote
0
down vote













[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....






share|improve this answer






















  • I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
    – Demian
    Nov 12 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 at 18:15










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',
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
);



);













draft saved

draft discarded


















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








up vote
0
down vote













[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....






share|improve this answer






















  • I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
    – Demian
    Nov 12 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 at 18:15














up vote
0
down vote













[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....






share|improve this answer






















  • I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
    – Demian
    Nov 12 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 at 18:15












up vote
0
down vote










up vote
0
down vote









[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....






share|improve this answer














[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....







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 12 at 16:09

























answered Nov 12 at 14:36









Demian

1637




1637











  • I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
    – Demian
    Nov 12 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 at 18:15
















  • I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
    – Demian
    Nov 12 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 at 18:15















I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
– Demian
Nov 12 at 16:10




I edited my answer and tested it on an extension here, everything worked correctly on background.js @wOxxOm
– Demian
Nov 12 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 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 at 18:15

















draft saved

draft discarded
















































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.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • 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.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto