首页 > 解决方案 > 在 SharePoint 列表中发布项目会给出 400 错误请求

问题描述

我已经 3 天试图将文本文件中的项目传输到 SharePoint 列表中,但现在我在控制台中有 400 错误请求错误。

这是我的代码:

    <script type="text/javascript">

      function createListItem() {
        //Fetch the values from the input elements  
        var eName = $('#title').val();  
        var eDesg = $('#name').val();  
        var eEmail = $('#email').val();  
        var eMobile = $('#moblie').val();  
        var eResidency = $('#Residency').val();  
        var eRequestDetails = $('#RequestDetails').val();  
        var eStatus = $('#Status').val(); 
        //alert(fullName);
        //alert(_spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/GetByTitle('ExitPermitRequest')/items");
        $.ajax({
            async: false,
            url: "http://stag.psa.gov.qa/en/_api/web/lists/GetByTitle('ndsList')/items",
            method: "POST",
            data: JSON.stringify({
                '__metadata': {
                    'type': 'SP.Data.ndsListListItem' // it defines the ListEnitityTypeName  
                },
                'Title': eName,
                'Full_x0020_Name': eDesg,
                'Moblile_x0020_Phone': eMobile,
                'E-Mail': eEmail,
                'Residency': Residency,
                'RequestDetails': eRequestDetails,
                'Status': eStatus
            }),
            headers: {
                "accept": "application/json;odata=verbose", //It defines the Data format   
                "content-type": "application/json;odata=verbose", //It defines the content type as JSON  
                "X-RequestDigest": $("#__REQUESTDIGEST").val() //It gets the digest value   
            },
            success: function (data) {
                alert("Item created successfully", "success"); // Used sweet alert for success message  
            },
            error: function (error) {
                alert("error occured"+ error);
            }
        })
    }


  </script>
<div id="insert1">  
        <table>  
            <tr>  
                <td> Title: </td>  
                <td>  
                    <input type="text" id="title" placeholder="Title" /> </td>  
            </tr>
            <tr>  
                <td> Full Name: </td>  
                <td>  
                    <input type="text" id="name" placeholder="Full Name" /> </td>  
            </tr>
            <tr>  
                <td> Email: </td>  
                <td>  
                    <input type="text" id="email" placeholder="Email" /> </td>  
            </tr> 
            <tr>  
                <td> Moblie Number: </td>  
                <td>  
                    <input type="text" id="moblie" placeholder="Moblie Number" /> </td>  
            </tr>
          <tr>
                   <td> Residency: </td>
          <td><select id="Residency">
            <option selected>In Qatar</option>
            <option>Outside Qatar</option>
          </select></td>
          </tr>
            <tr>  
                <td> RequestDetails: </td>
                <td>  
                    <input type="text" id="RequestDetails" placeholder="RequestDetails" /> </td>  
            </tr> 
                <tr>
                   <td> Status: </td>
          <td><select id="Status">
            <option selected>Not Started</option>
            <option>In Progress</option>
            <option>Pending</option>
            <option>Completed</option>
          </select></td>
          </tr>
            <tr>  
                <td></td>  
                <td>  
                    <button onclick="createListItem()">Click me</button>
                </td>  
            </tr>  
        </table>  
    </div> 

我试图输入硬编码的数据,但我没有工作。我不知道我的问题在哪里,如果 SharePoint 列有空格 , x0020是否正确?

标签: javascriptajaxrestapi

解决方案


如果您/用户属于太多 Active Directory 组,则可能会导致 400 bad request 错误

要解决此问题,Microsoft 提供了两种推荐的解决方案。第一个是删除多余的 Active Directory 组,第二个是配置注册表设置,然后重新启动服务器。

来源:

有两种选择。从用户的 AD 帐户中删除额外的 AD 组或在 IIS(Internet 信息服务器)Web 服务器上配置注册表设置。

IIS Web 服务器上的注册表位置:

HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\HTTP\Parameters

设置 MaxFieldLength 和 MaxRequestBytes 注册表项的值。

名称 值类型 值数据

最大字段长度 DWORD 65534

MaxRequestBytes DWORD 16777216


推荐阅读