Jquery定义了两次,导致SPServices无法正确加载。
控制台日志:
Uncaught TypeError: undefined is not a function index.html:77
LoadCat index.html:77
(anonymous function) index.html:107
n.event.dispatch jquery.js:3
r.handle
代码:
function LoadCat(cat) {
if (cat != null) {
var CAML = '<Query><Where><Eq><FieldRef Name="Department" /><Value Type="Text">' + cat + '</Value></Eq></Where></Query>';
}
else {
var CAML = '';
}
var liHtml = "Category: <select name="categoryselect" id="categoryselect">";
$().SPServices({
operation: "GetListItems",
async: false,
webURL: "PSS/StaffShop/",
listName: "Categories",
CAMLViewFields: "<ViewFields><FieldRef Name='Title' /></ViewFields>",
CAMLQuery: CAML,
completefunc: function (xData, Status) {
$(xData.responseXML).SPFilterNode("z:row").each(function () {
liHtml = liHtml + "<option value="" + $(this).attr("ows_Title") + "" >" + $(this).attr("ows_Title") + "</option>";
});
liHtml = liHtml + "</select>";
$("#cat").html(liHtml);
}
});
}
代码调用:
$('.area').click(function(){
alert($(this).attr("href"));
LoadCat();
});
代码在以下行失败:
$().SPServices({
然而
- JQuery is loaded
- SPServices is loaded
- Function is called in document ready
这里有完整的代码供感兴趣的人使用:http://pastebin.com/NvSCjV72
编辑:
似乎SPServices的引用在点击时丢失了?
有人能说明这件事吗?