How can I access jQuery from a Client Script

brandon_chamber
Kilo Contributor

Hello,

 

I've got a "Client Script" from which I'd like to access jQuery functionality.   How can I do this?   This is a normal ServiceNow client script, so I am already in an onChange() or onLoad() function and am not able to use the <g:include /> construct as this is not a UI page.   I see from inspecting the ServiceNow page that it looks like ServiceNow has setup a javascript include of <script></script> but when I try to reference window.jQuery or $j, I'm getting an undefined error.

 

Any sight to this would be helpful.

 

Thanks,

 

Brandon

11 REPLIES 11

geoffcox
Giga Guru

Many of our client scripts call jQuery (not "$").



Do you have the global client script "jquery-ui" defined?



Here is the header from ours:



/*!


* jQuery JavaScript Library v1.4.2


* http://jquery.com/


* Copyright 2010, John Resig


* Dual licensed under the MIT or GPL Version 2 licenses.


* http://jquery.org/license


* Includes Sizzle.js


* http://sizzlejs.com/


* Copyright 2010, The Dojo Foundation


* Released under the MIT, BSD, and GPL Licenses.


*


* Date: Sat Feb 13 22:33:48 2010 -0500


*/



I assume you can grab the actual script from somewhere.


Hmm.   No, we do not have the global jquery-ui defined client script.   I suppose I could always create one and put jquery in there.   I was just wondering if there was a way to access the jquery.min UI script that is already defined in the system.   The wiki/examples I found only demonstrate including this UI script from a jelly page.   The problem is the code I'm working in is not in a jelly page, but it is raw javascript in the onchange() or onload() functions of a normal client script.


We have the UI script "jquery.min" defined, but it is not set to global. Perhaps you could set it to global. I think it may use "$j" instead of "jQuery" to call it.


Thanks.   I'll look into that.