SP服务-对象不'我不支持这种方法

SP Services - Object doesn't support this method

本文关键字:不支持 方法 服务 对象 SP      更新时间:2023-09-26

当函数被调用时,我在这个函数上得到一个"Object不支持这个方法"错误

function LoadCat(cat) {
        if (cat != null) {
            var liHtml = "Category:  <select name='"categoryselect'" id='"categoryselect'">";
        var CAML = '<Query><Where><Eq><FieldRef Name="Department" /><Value Type="Text">' + cat + '</Value></Eq></Where></Query>';
        alert(CAML);
        } else {
        alert(cat);
        var CAML = '';
        }


       $().SPServices({
        operation: "GetListItems",
        async: false,
        webURL: "http://sp-app",
        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") + "</option>";
            });
            liHtml = liHtml + "</select>";
            $("#cat").html(liHtml);
        }
    });
    }

错误出现在$()上。SPServices({line

当cat为null或有值时,就会发生这种情况。

几个小时来我一直在为这个挠头!

SharePoint服务是在调用函数之前加载的!

似乎只有当我调用这个函数时才会出现错误:

  $(".area").click(function () {

      $(".area").parent("li").removeClass("active");
      $(this).parent("li").addClass("active");
      LoadCat();
    });
function LoadCat(cat) {
if (cat != null) {
        var liHtml = "Category:  <select name='"categoryselect'" id='"categoryselect'">";
    var CAML = '<Query><Where><Eq><FieldRef Name="Department" /><Value Type="Text">' + cat + '</Value></Eq></Where></Query>';
    alert(CAML);
    } else {
    alert(cat);
    var CAML = '';
    }
   $().SPServices({
    operation: "GetListItems",
    async: false,
    webURL: "http://sp-app",
    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") + "</option>";
        });
        liHtml = liHtml + "</select>";
        $("#cat").html(liHtml);
    }
});}
$(document).ready(function() {
    var subject = "Hi Subject!";
    var message = "Hi Message!";
    LoadCat(subject);        
});

看看浏览器中的javascript控制台,你会发现有用的错误。必须加载jQuery和SPServices。对于您的测试,您甚至可以使用jQuery和SPServices的cdn链接。

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery.SPServices/0.7.1a/jquery.SPServices-0.7.1a.min.js"></script>