0

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

OK, i came up with a solution by myself. The fix was to set url to Lists/'name of your list'. That did the work

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.