Hi,
i am trying to implement some jQuery Functions in my WebPart. I have two files:
1.) jQuery Library
2.) My custom .js file with my functions
This is my CodeBehind:
using System; using System.ComponentModel; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; namespace SiteMap.SiteMap { [ToolboxItemAttribute(false)] public class SiteMap : WebPart { protected override void CreateChildControls() { } protected override void OnLoad(EventArgs e) { base.OnLoad(e); base.EnsureChildControls(); if (!Page.IsPostBack) { ClientScriptManager csm = this.Page.ClientScript; Type csType = this.GetType(); if (!csm.IsClientScriptIncludeRegistered("jQuery")) { string url = "/_layouts/SiteMap/js/jQuery-1.11.0.js"; csm.RegisterClientScriptInclude("jQuery", url); Page.Response.Write("drin"); } if (!csm.IsClientScriptBlockRegistered("function")) { string url = "/_layouts/SiteMap/js/SiteMapJS.js"; csm.RegisterClientScriptInclude("function", url); } } } protected override void RenderContents(HtmlTextWriter writer) { base.RenderContents(writer); writer.AddAttribute("id", "SiteMap"); writer.RenderBeginTag(HtmlTextWriterTag.Div); writer.RenderEndTag(); } } }
This is my custom .js File:
$(document).ready(function () { $(document).ajaxStart(function () { console.log("ajaxStart"); }); $(document).ajaxStop(function () { console.log("ajaxStop"); }); console.log("0"); var url = location.protocol + "//" + location.host + L_Menu_BaseUrl; var JSONService = url + "/_vti_bin/SiteMap/SiteMapSvc.svc"; $.getJSON(JSONService + "/GetSiteCollections", function (data) { }) .done(function (data) { console.log("1"); if ((data !== undefined) && (data !== null)) { console.log("2"); var htmlTable = "<table id=\"tblGraduateProgram\" style=\"width:100%;border:1px solid #ccc;\">"; htmlTable += "<tr>"; htmlTable += "<th> </th>"; htmlTable += "<th>Teilnehmer</th>"; htmlTable += "</tr>"; $.each(data.GetSiteCollectionsResult, function (i, itemSiteCollections) { htmlTable += itemSiteCollections.Title; htmlTable += "</table>"; }); $(htmlTable).appendTo("#SiteMap"); }; }); });
But when i insert my Webpart i get the following error:
SCRIPT5007: The value of the property '$' is null or undefined, not a Function object
File: SiteMapJS.js, Line: 1, Column: 1
When i look at the HTML Code, both files are included successfully to the page. What is wrong here?
Best regards,
Yavuz B.
My Sharepoint and Enterprise 2.0 Blog http://www.bogazci.com |Microsoft Sharepoint Resources & Blog List