How can I access jQuery from a Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2014 07:39 AM
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
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2014 10:33 AM
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
* Copyright 2010, John Resig
* Dual licensed under the MIT or GPL Version 2 licenses.
* Includes Sizzle.js
* 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2014 10:40 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2014 10:53 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-30-2014 10:55 AM
Thanks. I'll look into that.