web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Add Jquery in HTML web Resource.

(0) ShareShare
ReportReport
Posted on by

Hi:
How can I include jQuery file in HTML web resource?

I included the file and it is shown in page Source (Inspect Element).

but when I call a method that is using jQuery, it is throwing.

ReferenceError: $ is not defined $(document).ready(function(){

although jquery in shown in page source.

any helpful suggestion is appericiated?

Thanks.

Here is complete source code.

<html><head>

		<script src="new_Jquery"></script>
		<script src="new_Json2"></script>
		<script>
		function loadTargets(){
			$(document).ready(function(){
			try{
				for(i = 1; i <= 10; i++){
					$('div.result').append("<div id='div"+ (i) +"'>Target-" + i +"</div>");
				}
				for(i = 1; i <= 4; i++){
					$('div.usres').append("<div id='div"+ (i) +"'>User-" + i +"</div>");
				}
				//ExecuteQuery("/new_studentSet?");
				}
				catch(exp)
				{
					alert("Exception: " + exp);
				}
			});
		}
		
		function ExecuteQuery(ODataQuery) {
			var serverUrl = Xrm.Page.context.getServerUrl();
			// Adjust URL for differences between on premise and online
			if (serverUrl.match(/\/$/)) {
			serverUrl = serverUrl.substring(0, serverUrl.length - 1);
			}
			var ODataURL = serverUrl + "/XRMServices/2011/OrganizationData.svc" + ODataQuery;
			$.ajax({
				type: "GET",
				contentType: "application/json; charset=utf-8",
				datatype: "json",
				url: ODataURL,
				beforeSend: function (XMLHttpRequest) {
					XMLHttpRequest.setRequestHeader("Accept", "application/json");
				},
				success: function (data, textStatus, XmlHttpRequest) {
					//
					// Handle result from successful execution
					//
					// e.g. data.d.results
					alert("Data Loaded Successfully, Thanks.");
				},
				error: function (XmlHttpRequest, textStatus, errorObject) {
					//
					// Handle result from unsuccessful execution
					//
					alert("OData Execution Error Occurred");
				}
			});
		}
		
		//
		// Error Handler
		//
		function ErrorHandler(XMLHttpRequest, textStatus, errorObject)
		{ alert("Error Occurred : " + textStatus + ": " + JSON.parse(XMLHttpRequest.responseText).error.message.value); }
		</script>
		<meta><meta><meta><meta></head>
		<body style="word-wrap: break-word;">
		<p>Show here a list of all targets...</p>
		<input type="button" value="Load Targets" onclick="loadTargets()">
		<div class="result"></div>
		<div class="usres"></div>
		</body></html>

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Community Member Profile Picture
    on at

    HI,

    I have already told you put the relative path of your jquery file web resource :

    in your case :

    <script src="../Jquery.js" type="text/javascript"></script>

    <script src="../Json2.js" type="text/javascript"></script>

  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Hello,
    Please provide screenshot of webresource's customization forms for your Html webresource and JQuery js webresource like following:

  • Community Member Profile Picture
    on at
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Please post the same screenshot for jquery.

  • Community Member Profile Picture
    on at
  • Verified answer
    a33ik Profile Picture
    84,331 Most Valuable Professional on at

    Try to use following html instead of yours:

    <html>
    <head>
        <title>Some title</title>
        <script src="new_Jquery" type="text/javascript"></script>
        <script src="new_Json2" type="text/javascript"></script>
        <script>
            function loadTargets() {
                for (i = 1; i <= 10; i++) {
                    $('div.result').append("<div id='div" + (i) + "'>Target-" + i + "</div>");
                }
                for (i = 1; i <= 4; i++) {
                    $('div.usres').append("<div id='div" + (i) + "'>User-" + i + "</div>");
                }
                //ExecuteQuery("/new_studentSet?");
            }
    
            function ExecuteQuery(ODataQuery) {
                var serverUrl = Xrm.Page.context.getServerUrl();
                // Adjust URL for differences between on premise and online
                if (serverUrl.match(/\/$/)) {
                    serverUrl = serverUrl.substring(0, serverUrl.length - 1);
                }
                var ODataURL = serverUrl + "/XRMServices/2011/OrganizationData.svc" + ODataQuery;
                $.ajax({
                    type: "GET",
                    contentType: "application/json; charset=utf-8",
                    datatype: "json",
                    url: ODataURL,
                    beforeSend: function (XMLHttpRequest) {
                        XMLHttpRequest.setRequestHeader("Accept", "application/json");
                    },
                    success: function (data, textStatus, XmlHttpRequest) {
                        //
                        // Handle result from successful execution
                        //
                        // e.g. data.d.results
                        alert("Data Loaded Successfully, Thanks.");
                    },
                    error: function (XmlHttpRequest, textStatus, errorObject) {
                        //
                        // Handle result from unsuccessful execution
                        //
                        alert("OData Execution Error Occurred");
                    }
                });
            }
    
            //
            // Error Handler
            //
            function ErrorHandler(XMLHttpRequest, textStatus, errorObject)
            { alert("Error Occurred : " + textStatus + ": " + JSON.parse(XMLHttpRequest.responseText).error.message.value); }
        </script>
    </head>
    <body style="word-wrap: break-word;">
        <p>Show here a list of all targets...</p>
        <input type="button" value="Load Targets" onclick="loadTargets()">
        <div class="result"></div>
        <div class="usres"></div>
    </body>
    </html>


  • Community Member Profile Picture
    on at
  • Community Member Profile Picture
    on at
  • Community Member Profile Picture
    on at

    @Andrii...did you understand the problem?

  • Suggested answer
    Community Member Profile Picture
    on at

    Try to use hosted libraries if you can not find from CRM location :

    <script src="cdnjs.cloudflare.com/.../json2.js&quot; type="text/javascript"></script>

    <script src="ajax.googleapis.com/.../jquery.min.js&quot; type="text/javascript"></script>

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans