I created an Sharepoint-hosted application with angularjs.

And ran into a problem, my post request returns status -1, but saves the data. How to fix it?

My Lists posted on SPHostUrl.

Here is my base post service

     var postRequest = function (data, url) {
        var deferred = $q.defer();
            url: baseUrl + url,
            method: "POST",
            headers: {
                "accept": "application/json;odata=verbose",
                "X-RequestDigest": document.getElementById("__REQUESTDIGEST").value,
                "content-Type": "application/json;odata=verbose"
            data: JSON.stringify(data)
        }).then(function (result) {
        }, function (result) {
        return deferred.promise;

And here is post service

    var addNew = function (certificate) {
        var data = {
            __metadata: { 'type': 'SP.Data.CertificatesListItem' },
            FullName: certificate.FullName,
            TypeOfCertificateId: certificate.TypeOfCertificateId,
            Validity: certificate.Validity
        var url = '/_api/SP.AppContextSite(@target)/web/lists' + "/GetByTitle('Certificates')/Items?@target='" + window._spApplicationInfo.SPHostUrl + "'";
        return baseService.postRequest(data, url);

It was my fault.

I used simple div's and button without any type.

My solution is to add $event.preventDefault():


<button class="btn btn-warning" data-ng-click="addTypeOfCertificate(typeOfCertificate, $event)">Сохранить</button>

and addTypeOfCertificate function:

        $scope.addTypeOfCertificate = function (typeOfCertificate, $event) {


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.