Hli Archives: Lub ib hlis ntuj 2015

HTTP 406 Yuam kev thaum uas siv cov Angular $http.get tiv thaiv SharePoint so kawg ntsiab lus

Hloov tshiab: Marc AD ndersson taw tes qhia tawm no zoo kawg thiab daim info: http://blogs.Office.com/2014/08/13/json-Light-Support-rest-sharepoint-API-Released/. Uas piav txog heev :).

Uas tej zaum yuav tau lub npe phem ntawm ib cov ncej blog puas! Anyhoo.

Kuv mas ua rau kuv prototyping rau thaj O365. Kuv tau kuv tus kheej lom kom kuv tsis muaj yuav txhawj xeeb txog koj rau leej twg. Ua tus ib cag-nco thaum peb hu kwv ncig cov cav tov virtual rau peb laptops nrog NTXHUAB – SQL neeg rau zaub mov, IIS, txiav txim siab seb vs Hyper-V. VMWare? Anyhoo...

Kuv tau tsim ib qho app Angular siv nyob rau hauv qhov chaw uas puas, cov lwm yam, qhov no:

$http.Get(serverUrl)
.zoo(muaj nuj nqi(cov ntaub ntawv, xwm txheej, headers, config) {

Var getLinksResponse = ntaub ntawv;

getLinksResponse.value.forEach(muaj nuj nqi(theResult) {

// li ntawd thiab ces froth

Qhov no yog ua hauj lwm xwb fine ob hom SharePoint nyob rau hauv tej kev kawm. Txawm li cas los, Thaum twg kuv colleague ported nws mus rau ib Cloudshare lom, nws tsis yog ib tug HTTP 406 yuam kev (uas yog thawj zaug kuv puas tau mus txog ntawd ib tug, vim li ntawd... yay, tej zaum). Peb puas muaj me ntsis kev soj ntsuam thiab pom tias header uas muaj "Txais" tus ntawd tawm. SharePoint hauv Internet yog txawm zoo siab nrog:

Txais: daim ntawv thov/json

Tab sis qhov cloudshare lom (Nws yog ib qho SP rau prem, hosted rau ib tug neeg rau zaub mov virtual) xav qhov classic "odata = verbose" ntxiv rau kom zoo:

Txais: daim ntawv thov/json;odata = verbose

Kho uas, peb ntxiv cov header zoj:

Var config = {headers: {
'Lees': ' thov/json;odata = verbose'
}
};

$http.Get(serverUrl,config)
.zoo(muaj nuj nqi(cov ntaub ntawv, xwm txheej, headers, config) {

Var getLinksResponse = ntaub ntawv;

getLinksResponse.value.forEach(muaj nuj nqi(theResult) {

// li ntawd thiab ces froth

Uas tau mus tua ntawm tus 406, tiam sis nws kuj hloov cov hom ntawv uas yuav teb. Yog xav paub ntxiv … verbose. (haha!) Muaj ntau yam hloov ntxiv yuav tsum thiab nov yog qhov tshwm sim zaum kawg:

Var config = {headers: {
'Lees': ' thov/json;odata = verbose'
}
};

$http.Get(serverUrl,config)
.zoo(muaj nuj nqi(cov ntaub ntawv, xwm txheej, headers, config) {

Var getLinksResponse = ntaub ntawv;

getLinksResponse.d.Results.forEach(muaj nuj nqi(theResult) {

// li ntawd thiab ces froth

Qhov no tsuas txia ntshis ua ib tug 30 teeb meem feeb rau peb, kom peb lucked. Hopefully ib tug neeg pom qhov no pab tau.

</kawg>

How-to: Pab kom muaj ntau yam Angular SharePoint Web nyob rau ib sab

No blog posts piav li cas yuav muaj ntau yam Angular.js raws li qhov chaw web site SharePoint (hais los ntawm ib editor cov Web site qhov) nyob rau ib sab. Kuv hu editor cov Web site qhov (CEWP) uas chiv keeb JavaScript ua tau siv lub moj khaum Angular.js ib "Angular Web txoj kev."

Angular txoj kev bootstrap yog super yooj yim thiab li xwb txhua piv txwv uas koj pom hauv lub internets huas muaj tej yam zoo li no:

<html ng-app = 'myApp'>

<blah /><blah /><blah />

</html>

Qhov no lov, Txawm li cas los, Yog koj xav pab kom ntau CEWP ntawv nthuav ntau yam angular web nyob rau ib sab. Angular yuav yeej tsuas bootstrap tiv thaiv cov ng app thawj tswj nws pom – kawg as of angular version 1.3.6. Cov tshuaj yog zoo nkauj yooj yim – manually bootstrap koj chaws xwb. Cov saum no tam sim no nws ho hloov kev tej yam zoo li no:

<lub cev>
<d
IV daim id =”bootstrapHere” ng maub los =”myController ua theController”>
<blah /><blah /><blah />
</div>
</lub cev>

<tsab ntawv src =”//ajax.googleapis.com/ajax/libs/angularjs/1.3.6/angular.js”></tsab ntawv>

<tsab ntawv>
angular.bootstrap(angular.element(document.getElementById(“bootstrapHere”)),['myApp']);
</tsab ntawv>

Yeej, tsis txhob siv ng app rau lub caij ua koj bootstrapping, koj npuaj ib tug ID rau tus ntawd lub caij. Ces, siv cov bootstrap() txoj kev angular rau nws tus kheej uas tswj cov bootstrapping txheej txheem lub sij hawm mus dhia. Kuv twb sim no nrog peb yam txawv Angular web nyob rau ib sab thiab nws ua haujlwm ib lub nplhaib.

</kawg>

undefinedSubscribe rau kuv blog.

Raws li kuv nyob Twitter tom http://www.twitter.com/pagalvin