mardi 13 janvier 2015

Ajax Post not working



I created a list from appweb to hostweb and the list url is without "lists/" I then trying to use ajax call post on my startsite (not from the app) but i get following error: 400 bad request x.support.cors.e.crossDomain.send


SharePoint Online



function saveSelectedAnswer(selectedAnswer) {
var requestUri = _spPageContextInfo.webAbsoluteUrl + "/_api/web/lists/getByTitle('PollUserData')/items/";
var pollData = {
__metadata: {
"type": "SP.Data.PollUserDataListItem"
},
Title: 'test',
UserID: userGuid, //text
Question: allQuestionsArray[0].Question, //text
QuestionAnswers: allQuestionsArray[0].Answers, //text
Answer: selectedAnswer, //text
QuestionID: allQuestionsArray[0].ID //number
//Check field types if error
};
var requestBody = JSON.stringify(pollData);
var requestHeaders = {
"ACCEPT": "application/json;odata=verbose",
"X-RequestDigest": $("#__REQUESTDIGEST").val(),
}
$.ajax({
url: requestUri,
type: "Post",
async: false,
contentType: "application/json;odata=verbose",
data: requestBody,
headers: requestHeaders,
success: function() {
console.log("data saved");
$("#weeklyPollContainer").hide();
showLoader();
},
error: function(xhr, thrownError) {
alert("Error save answers " + xhr.status + " " + thrownError);
}
});
}







0 commentaires:

Enregistrer un commentaire