JQuery操作SharePoint Web Services之添加列表数据

上一篇中我介绍了JQuery操作SharePoint Web Services之查询列表数据 ,这一篇我介绍一下添加列表数据 。

一些基本的要求和上一篇一样,效果图如下:

输入 Title和City的值,列表项的数据就会更新。(不过需要你刷新一下页面,原理嘛,大家都知道)

代码如下:

 

Title: < input type = " text "  id = " txtNewTitle "   / > <br  / >
City: < input type = " text "  id = " txtNewCity "   / > <br  / >
< input type = " button "  id = " btnAddCity "  value = " Add New City "  onclick = " AddCity('txtNewTitle','txtNewCity') "   / > 

< script language = " javascript "  src = " /js/jquery-1.3.2.min.js "  type = " text/javascript " >< / script>
< script language = " javascript "  type = " text/javascript " >

function  AddCity(titleId,cityId) {
     var  title = $( " # " + titleId).val();
     var  city = $( " # " + cityId).val();
     var  batch  =
         " <Batch OnError='Continue'> \
        <Method ID='1'  Cmd='New' > \
        < Field Name='Title'> " + title + " </Field > \
        < Field Name='City'> " + city + " </Field > \
        </Method> \
        </Batch> " ;    

    var  soapEnv  =
         " <soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
             <soapenv:Body> \
            < UpdateListItems  xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
            <listName>TestList</listName> \
            < updates> "   +  batch  +   " </updates> \
            </UpdateListItems> \
            </soapenv:Body> \
            </soapenv:Envelope> " ;

                
    $.ajax({
        url:  " /sites/learner/_vti_bin/lists.asmx " ,
        beforeSend:  function (xhr) {
            xhr.setRequestHeader( " SOAPAction " ,
             " http://schemas.microsoft.com/sharepoint/soap/UpdateListItems " );
        },
        type:  " POST " ,
        dataType:  " xml " ,
        data: soapEnv,
        complete: processResult,
        contentType:  " text/xml; charset=utf-8 "
    });

}


function  processResult(xData, status) {
    alert(status);
}
< / script>

 

需要注意的地方已经在代码中标识。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值