Angularjs $ http在sharepoint 2013中返回状态代码0和数据为null [英] Angularjs $http returns status code 0 and data as null in sharepoint 2013

查看:132
本文介绍了Angularjs $ http在sharepoint 2013中返回状态代码0和数据为null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在SharePoint 2013中使用带有http调用的rest api将记录插入多个列表时,我遇到了一个问题。



我写了下面提到的常用方法将输入参数作为数据和网址。



  var  postRequest = < span class =code-keyword> function (data,url){
var deferred = $ q.defer();
$ http({
url:baseUrl + url,
method: POST
标题:{
接受:< span class =code-string> application / json; odata = verbose
Content-Type application / json; odata = verbose
X-RequestDigest :jQuery( #__ REQUESTDIGEST)。val(),
If-Match *
},
data: JSON .stringify(data)
})。success( function (result){
alert(result.d.Id);
deferred.resolve(result.d.Id);
})。error( function (结果,状态){
alert(status + result);
deferred.reject(status );
});
return deferred.promise;
};



使用上面的代码我将数据插入到列表A中,一旦将记录插入列表a,使用项目ID我正在插入记录在列表b中有附加字段和列表C.



我调用上面提到的常用方法。



 $ scope.submitData =  function (LSSDeal,lssIds,amIds){
var submitDataPromise = lssDealService.submitLSS(LSSDeal,lssIds,amIds);
submitDataPromise.then( function (transactionResponse){
var transactionId = transactionResponse;
$ scope.AddtoPaymentList(LSSDeal,transactionId);
$ scope.AddToHistory(LSSDeal,transactionId);

}, function (错误){
alert( 提交交易数据时出错 +错误);
});
};



我能够获得第一个请求的事务ID,它将在列表A中插入记录。获取ID后,我将调用剩余的两个方法。< br $>


 $ scope.AddtoPaymentList =  function (LSSDeal,transactionId){
var paymentlistPromise = lssDealService.saveToPaymentList(LSSDeal,transactionId);
paymentlistPromise.then( function (paymentlistResponse){
var paymentId = paymentlistResponse;
alert( LSS交易已添加到包含交易ID的付款清单中: + transactionId );
}, function (错误){
alert( 插入付款清单数据时出错 +错误);
});
};
$ scope.AddToHistory = function (LSSDeal,parentListId){
var historyPromise = lssDealService.saveToHistory(LSSDeal,parentListId);
historyPromise.then( function (historyResponse){
var historyId = historyResponse;
alert( 已将历史记录中的LSS交易添加到历史记录中ID: + historyResponse) ;

}, function (错误){
alert( 插入历史数据时出错 +错误);
});

};



对于剩下的两种方法,我总是收到错误消息,状态为零,数据为空。



只是对于病房的第二次请求它的错误块但是记录插入成功。



但是当我调试成功消息时。请指导我。



提前致谢。



参考文献:http://www.codeproject。 com / Articles / 1002526 / SharePoint-and-Angularjs



我尝试过:



我尝试过使用ajax调用和超时选项更改http调用。

解决方案

q.defer();


http({
url:baseUrl + url,
method: POST
标题:{
接受 application / json; odata = verbose
Content-Type application / JSON;的OData =详细
X-RequestDigest:jQuery( #__ REQUESTDIGEST)。val(),
If-Match *
},
数据: JSON .stringify(data)
})。success( function (结果){
alert(result.d.Id);
deferred.resolve(result.d.Id);
})。error( function (结果,状态){
alert(status + result);
deferred.reject(status );
});
return deferred.promise;
};



使用上面的代码我将数据插入到列表A中,一旦将记录插入列表a,使用项目ID我正在插入记录在列表b中有附加字段和列表C.



我调用上面提到的常用方法。



 


scope.submitData = function (LSSDeal,lssIds,amIds){
var submitDataPromise = lssDealService.submitLSS(LSSDeal,lssIds,amIds);
submitDataPromise.then( function (transactionResponse){
var transactionId = transactionResponse;

I am facing an issue when inserting records in to multiple lists using rest api with http calls in SharePoint 2013.

I have written common method mentioned below which will take input params as data and url.

var postRequest = function (data, url) {
               var deferred = $q.defer();
               $http({
                   url: baseUrl + url,
                   method: "POST",
                   headers: {
                       "Accept": "application/json;odata=verbose",
                       "Content-Type": "application/json;odata=verbose",
                       "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(),
                       "If-Match": "*"
                   },
                   data: JSON.stringify(data)
               }).success(function (result) {
                   alert(result.d.Id);
                   deferred.resolve(result.d.Id);
               }).error(function (result, status) {
                   alert(status + result);
                   deferred.reject(status);
               });
               return deferred.promise;
           };


Using the above code I am inserting data in to list A, once record has been inserted in to list a, With item id of I am inserting record in list b with additional fields and list C.

I am calling above common method which is mentioned as below.

$scope.submitData = function (LSSDeal, lssIds, amIds) {
            var submitDataPromise = lssDealService.submitLSS(LSSDeal, lssIds, amIds);
            submitDataPromise.then(function (transactionResponse) {
                var transactionId = transactionResponse;
                $scope.AddtoPaymentList(LSSDeal, transactionId);
                $scope.AddToHistory(LSSDeal, transactionId);

            }, function (error) {
                alert("error in submitting transaction data" + error);
            });
        };


I am able to get transaction id for first request which will insert record in list A.After getting ID I am calling remaining two methods.

$scope.AddtoPaymentList = function (LSSDeal, transactionId) {
               var paymentlistPromise = lssDealService.saveToPaymentList(LSSDeal, transactionId);
               paymentlistPromise.then(function (paymentlistResponse) {
                   var paymentId = paymentlistResponse;
                   alert("LSS Deal has been Added to payment list with transaction Id:" + transactionId);
               }, function (error) {
                   alert("error in inserting payment list data" + error);
               });
           };
           $scope.AddToHistory = function (LSSDeal, parentListId) {
               var historyPromise = lssDealService.saveToHistory(LSSDeal, parentListId);
               historyPromise.then(function (historyResponse) {
                   var historyId = historyResponse;
                   alert("LSS Deal has been Added to history with history Id:" + historyResponse);

               }, function (error) {
                   alert("error in inserting history data" + error);
               });

           };


For remaining two methods I am always getting error message as status zero and data null.

Simply for second request on wards its going error block but records are inserting successfully.

But when I am debugging getting success messages. Please guide me.

Thanks in advance.

References: http://www.codeproject.com/Articles/1002526/SharePoint-and-Angularjs

What I have tried:

I have tried by changing http call with ajax call and timeout option.

解决方案

q.defer();


http({ url: baseUrl + url, method: "POST", headers: { "Accept": "application/json;odata=verbose", "Content-Type": "application/json;odata=verbose", "X-RequestDigest": jQuery("#__REQUESTDIGEST").val(), "If-Match": "*" }, data: JSON.stringify(data) }).success(function (result) { alert(result.d.Id); deferred.resolve(result.d.Id); }).error(function (result, status) { alert(status + result); deferred.reject(status); }); return deferred.promise; };


Using the above code I am inserting data in to list A, once record has been inserted in to list a, With item id of I am inserting record in list b with additional fields and list C.

I am calling above common method which is mentioned as below.


scope.submitData = function (LSSDeal, lssIds, amIds) { var submitDataPromise = lssDealService.submitLSS(LSSDeal, lssIds, amIds); submitDataPromise.then(function (transactionResponse) { var transactionId = transactionResponse;


这篇关于Angularjs $ http在sharepoint 2013中返回状态代码0和数据为null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆