Quantcast
Channel: CRM Development forum
Viewing all articles
Browse latest Browse all 9244

Why do I always get an Object expected error when I try to use jQuery

$
0
0

I have a web resource which is an HTML page. That HTML page works perfectly in other environments (LAMP mainly) and uses jQuery to drive a lot of interaction on the page.

I then include that page on a CRM form, remove the reference to jQuery from the page and add the jQuery library as a separate resource. Now whenever I try to use that form I get errors which are "Object expected" and appear to be that the page objects to the basic "$( ... )" jQuery selector suggesting that it has not loaded the jQuery library at all.

So my code starts as ...

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd"><html><head><title>Untitled Document</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><style type="text/css">
.timeslot { 
	width : 12px; 
	border-left: 2px solid #FFFFFF;
	border-bottom: 2px solid #EEEEEE;
}
.hourstart {border-left: 2px solid #BBBBBB; }</style><script type="text/javascript">
	$().ready(function($) {
		$('.timeslot').css("background-color", "#DDDDDD");


and it bombs at the $().ready call when in CRM. jQuery is included in the supposedley available libraries for the page. OK maybe something is loading in the wrong order but I also invoke the same calls later from a button. By this time everything should have loaded but I get the same errors.

Now I have tried moving all that code into a separate library and invoking that from a body onload call in the web page but then I get the same "object expected" error when CRM gets to the <BODY> tag of the web page. What on earth does CRM want here!

Now elsewhere I have attached jQuery to controls and it works very well. A little more confusingly than just writing a real web page but nonetheless it works. It appears to be solely to do with trying to apply it to an entire web page included as a web resource. How do I call jQuery from a webResource included on a page?

The code itself is correct because I can make this work by copying the jQuery libraries into every single web resource that I want to use in CRM but that seems an insane approach. Equally if I leave the <Script reference in a point to code.jquery.com to get an online copy it fails. So it behaves as though CRM is just ignoring all attempts to reference a library from a web resource.


Viewing all articles
Browse latest Browse all 9244

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>