Я 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>
Я пытался ввести данные как жестко закодированные, но у меня ничего не получалось.Я не знаю, где моя проблема, а также x0020 правильно, если в столбце SharePoint есть пробел?