TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Mark Lalich
NA
14
1k
Erros when adding to SP list through AngularJS.
Dec 28 2018 10:46 AM
I'm just trying to submit a simple item to a sharepoint online list. Here's the code I have to do this.
app.factory(
"organizationsSrvc"
, [
'$rootScope'
,
'$http'
,
function
($rootScope, $http) {
var
listName =
"Organizations"
;
var
organizationsService = {};
//Organization operations
var
organizations =
null
;
organizationsService.add =
function
(organization) {
var
data = JSON.stringify(organization);
data = data.replace(/[{}]/g,
''
);
var
datavalue =
"{__metadata:{'type':'SP.Data.'"
+ listName +
"'.ListItem'},"
+ data +
"}"
;
console.log(datavalue);
$http({
url: _spPageContextInfo.webAbsoluteUrl +
"/_api/web/lists/GetByTitle('"
+ listName +
"')/items"
,
method:
'POST'
,
headers: {
"Accept"
:
"application/json;odata=verbose"
,
"Content-Type"
:
"application/json;odata=verbose"
,
"X-RequestDigest"
: $(
"#__REQUESTDIGEST"
).val(),
"X-HTTP-Method"
:
"POST"
},
data: datavalue
}).then(
function
success(response) {
console.log(
"[add Organization] POST worked"
);
console.log(
"[add Organization] New Id = "
+ response.Id);
debugger
;
},
function
error(response) {
console.log(
"[add Organization] Error = "
+ response);
debugger
;
})
console.log($http);
debugger
;
};
return
organizationsService;
}]);
When running this I get the following output in console.
{__metadata:{'type':'SP.Data.'Organizations'.ListItem'},"title":"test"}
organizations.controller.js:69 ƒ $http(requestConfig) {
if (!angular.isObject(requestConfig)) {
throw minErr('$http')('badreq', 'Http request configuration must be an object. Received: {0}', requestConfig);
…
POST ....... 400
From what I'm seeing in this output, it looks like It's outputting line 14, then line 33, then hits the error on line 31. It's saying it's a 400 error.
Any help is appreciated!!
Reply
Answers (
1
)
Timer in Angular
Code to clear mat radio button select.