【问题标题】:How to update a page's content using SPServices?如何使用 SPServices 更新页面内容?
【发布时间】:2014-10-03 14:19:13
【问题描述】:

我正在尝试使用 SPServices 更新页面的内容。

当我运行我的代码时,它确实会更新正确的页面,但不会更新内容,而是删除内容。

var newContent = "<p>This is a test</p>";

$().SPServices({
   operation: "UpdateListItems",
   listName: "Pages",
   ID: itemID,
   async: false,
   valuepairs: [["PublishingPageContent", newContent]]
})

【问题讨论】:

    标签: sharepoint spservices


    【解决方案1】:

    这是因为 UpdateListItems 操作需要 HTML 转义字符串作为参数。

    以下函数可用于编码 HTML 字符串:

    function htmlEncode(value){
      //create a in-memory div, set it's inner text(which jQuery automatically encodes)
      //then grab the encoded contents back out.  The div never exists on the page.
      return $('<div/>').text(value).html();
    }
    

    Source

    固定示例

    var itemID = <Your item id goes here>;
    var newContent = "<p>Some content goes here</p>";
    $().SPServices({
       operation: "UpdateListItems",
       listName: "Pages",
       ID: itemID,
       async: false,
       valuepairs: [["PublishingPageContent", htmlEncode(newContent)]],
       completefunc: function(xData, Status)
       {
             console.log('Page has been updated');      
       }
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-14
      • 1970-01-01
      • 2017-12-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-09
      相关资源
      最近更新 更多