问题
I've been pulling my hair out with this. We have an implementation of bxslider in a SharePoint 2013 home page. This work was completed by my now departed collegue, so not my work, but .... it was finished and working.
Now though I get a runtime error when calling onSliderLoad callback function which calls slider.goToNextSlide();
Extract from Debug Output window VS: 0x800a138f - JavaScript runtime error: Unable to get property 'goToNextSlide' of undefined or null reference
I've pretty much ruled out a code change because I've reverted the source code back months and also restored a very old snapshot into the virtual SharePoint server. These all still experience the same new issue. I also tried this trick on our staging server which hasn't had any newly released code for a while. This host is now experiencing the same issue. Only thing I can think is that there is a external change which is causing this issue, but what I have no idea.
I get different errors from Firebug and IE10 (It's SharePoint you have to test and debug in IE as well ;-))


Extract from FeedsRotator.ascx (Webpart on Home.aspx)
var slider= $('#slider2').bxSlider({
auto: true,
controls: false,
pager:false,
pause: 10000,
slideWidth: (sir ? sirina:300),
slideHeight: 450,
randomStart: true,
autoHover: true,
onSliderLoad: function (currentIndex) {
slider.goToNextSlide(); //This is line 1024
},
Extract from BxSlider.css
#slider1 {
margin:0;
padding:0;
}
.bx-wrapper {
position: relative;
margin: 10px;
padding: 0;
*zoom: 1;
}
.bx-wrapper img {
max-width: 100%;
display: block;
}
Forgot to say we're using jquery 1.9.1.
回答1:
So, I was completely barking up the wrong tree with the clientside code. It was infact that the Annoucements List items which populate the news slider had expired 5 days ago.

string Qry = " <Where><Geq><FieldRef Name='Expires' /><Value IncludeTimeValue='FALSE' Type='DateTime'>{0}</Value></Geq></Where>";
protected void Page_Load(object sender, EventArgs e)
{
if (!((Page)System.Web.HttpContext.Current.CurrentHandler).IsPostBack)
{
DisplayAnnouncements();
}
}
private void DisplayAnnouncements()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
SPList list = web.Lists["Announcements"];
SPQuery query = new SPQuery();
query.RowLimit = 10;
query.Query = string.Format(Qry, DateTime.Now.ToString("yyyy-MM-dd"));
rep1.DataSource = list.GetItems(query).GetDataTable();
rep1.DataBind();
}
}
}
);
}
So now I have to decide how to handle this
Option 1 (find the most recently expired announcements):
private void DisplayAnnouncements()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
SPList list = web.Lists["Announcements"];
SPQuery query = new SPQuery();
query.RowLimit = 10;
DateTime queryDate = DateTime.Now;
query.Query = string.Format(Qry, queryDate.ToString("yyyy-MM-dd"));
while (list.GetItems(query).Count == 0 && queryDate > new DateTime(2000, 1, 1)) //Stop an infinitive loop where list is empty
{
TimeSpan oneDay = new TimeSpan(1, 0, 0, 0);
queryDate = queryDate - oneDay;
query = new SPQuery() { Query = string.Format(Qry, queryDate.ToString("yyyy-MM-dd")) };
}
rep1.DataSource = list.GetItems(query).GetDataTable();
rep1.DataBind();
}
}
}
);
}
Option 2 (Display No News)
private void DisplayAnnouncements()
{
SPSecurity.RunWithElevatedPrivileges(delegate()
{
using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
using (SPWeb web = site.OpenWeb(SPContext.Current.Web.ID))
{
bool oldAllowUnsafeUpdates = web.AllowUnsafeUpdates;
web.AllowUnsafeUpdates = true;
web.Update();
SPList list = web.Lists["Announcements"];
SPQuery query = new SPQuery();
query.RowLimit = 10;
DateTime queryDate = DateTime.Now;
query.Query = string.Format(Qry, queryDate.ToString("yyyy-MM-dd"));
if (list.GetItems(query).Count == 0)
{
SPListItem noNewsListItem = list.AddItem();
noNewsListItem["Title"] = "NoCurrentNews";
noNewsListItem["MainDisplayImage"] = "<img src=\"/sites/OMGIntranet/SiteAssets/NO-CURRENT-NEWS-STORIES.jpg\"></img>";
noNewsListItem["Expires"] = DateTime.MaxValue;
noNewsListItem.Update();
}
rep1.DataSource = list.GetItems(query).GetDataTable();
rep1.DataBind();
web.AllowUnsafeUpdates = oldAllowUnsafeUpdates;
}
}
}
);
}
来源:https://stackoverflow.com/questions/20640473/bxslider-stopped-working-2-days-ago-with-no-code-changes