2013-07-07 2 views
0

Sharepoint Rest 서비스를 사용하여 목록 항목을 업데이트하고 있습니다. 업데이트를 수행하려면 SP.RequestExecutor 개체에서 executeAsync 함수를 사용하고 있습니다. 코드가 제대로 작동했지만 오늘 테스트를하는 동안 ListItems가 업데이트되지 않고 executeAsync 함수가 제대로 작동하고 있음을 알았습니다 (성공 함수로 가고 오류가 없었습니다).sharepoint rest services - executeAsync not working

function ActualizarDatosListaConItemType(urlSitio, nomlista, id, metadata, funcionExito, funcionError,  itemType, esAsync) { 
// Prepping our update 
var item = $.extend({ "__metadata": { "type": itemType } }, metadata); 
var executor = new SP.RequestExecutor(urlSitio); 
executor.executeAsync({ 
         url: urlSitio + "/_api/web/lists/getbytitle('" + nomlista + "')/items('" + id + "')", 
         type: "POST", 
         contentType: "application/json;odata=verbose", 
         data: JSON.stringify(item),       
         headers: { 
            "Accept": "application/json;odata=verbose", 
            "X-RequestDigest": $("#__REQUESTDIGEST").val(), 
            "X-HTTP-Method": "MERGE", 
            "If-Match": "*" 
            }, 
    success: function (data) { funcionExito(data); }, 
    error: function (data) { funcionError(data); } 
}); 
} 

내 코드는 괜찮습니다. T_T를 도와주세요.

답변

4

나는 며칠 동안이 문제를 해결해 왔으며 SP.RequestExecutor는 일반적인 '직접적인'아약스 쿼리와 약간 다른 매개 변수 이름을 가지고 있습니다. 예를 들어

대신 사용

method: "POST" 

type: "POST" 

실제 데이터 패키지 대신 게시하는

data: JSON.stringify(item) 

사용

body: JSON.stringify(item) 

마지막으로 GetByTitle 포함 함수는 괄호 안에 title 매개 변수에 따옴표를 사용하지만 항목은 그렇지 않습니다. 그래서 그 대신

.../항목 ('123')

사용

.../항목 (123)

완성도를 들어

가, 여기에 내가 업데이트하는 데 사용되는 블록

new SP.RequestExecutor(closureThis.appweburl).executeAsync(
     { 
      url: closureThis.appweburl + "/_api/SP.AppContextSite(@target)/web/lists(guid\'" + listIdGuid + "\')/items(" + itemId + ")[email protected]='" + closureThis.hostweburl + "'", 
      method: "POST", 
      headers: { 
       "accept": "application/json;odata=verbose", 
       "content-type": "application/json;odata=verbose", 
       "X-RequestDigest": closureThis.getDigestValue(), 
       "X-HTTP-Method": "MERGE", 
       "If-Match": "*" 
      }, 
      body: updateBlock, 
      success: function (data) { closureThis.updateDataObjectCallback(data); }, 
      error: spRequestorErrorHandler 
     } 
    ); 
closureThis 내가 저장 셰어 변수에 사용하는 객체입니다

하고 처리 할 콜백,369 다음 SP.RequestExecutor 개체가있는 도메인에서 자바 스크립트를 사용하여 나머지를 통해

"{\"__ 메타 데이터 \ ": {\"유형 \ "\"SP.Data.TasksListItem \ updateBlock이

내 updateBlock 값이이처럼 보이는 JSON.stringify (데이터) 값을입니다"}, \"Title \ ": \"First Task \ "}"

+0

나는 이것을 대답으로 삼을 것입니다. 문제는 정확히 내 것이 아니 었습니다. 친구의 문제였습니다. 그는 execute 메쏘드가 마술처럼 다시 작동하기 시작했다고 말했다 ... w/e –