Qeb Archives: JavaScript

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>

Angular tsis nyob hauv lub IE9 Bootstrap

Kuv twb tau ua si ib ncig nrog Angular.js tus kawg ntev thaum thiab lub neej ntawm kuv, Kuv tsis tau kuv lub apps Angular tua tawm rau hauv IE9.  Lawv cov haujlwm fine hauv IE11 tab sis IE9 yuav cia li qhia lub curly kev zawm hniav thiab cov khoom zoo sib xws.

Kuv nrhiav ib ncig thiab nrhiav tsis tau leej twg complaining txog nws qhov teeb meem.  Nws ua haujlwm fine hauv Chrome, IE11, IE9 xwb tsis.

Kuv tug ces muab pov tseg los ntawm lub fact tias tus IE console twb muab rau kuv uas tsis zoo li no:

SEC7111: HTTPS kev ruaj ntseg yog nyom ntawm Res/sx /://ieframe.dll/forbidframing.htm

Qhov yuam kev tas kuv xav yog muaj tej teeb meem daus lub angular los yog qiv uas kuv xav tau.  Thaum nws puv, qhov no twb tsis tau qhov no.

Yog tshwm nyob ib ncig ntawm lub internets, Kuv thaum kawg pom tias cov kab lus uas kuv yuav tsum tau mus nrhiav tau "bootstrap" thiab cov uas mag li tus bootstrapping twb tsis.  Thaum kawg, kuv qhov teeb meem yog hais tias kuv decorated tau kuv <html> lossis nrog tus ng app attribute, raws li nyob rau hauv:

<html ng-app = "MatrixApp">

Qhov tshij, uas tsis ua hauj lwm rau IE9.  Xwb, Qhwv tas tas cov HTML rau hauv kuv lub <lub cev> hauv ib div thiab cov neeg ua tim khawv MatrixApp li ntawd mas.

Teeb meem solved.

Hopefully no yam neeg tej kev tu siab.

</kawg>

Zuj zus khiav / Mus tu JavaScript coj

Kuv colleague, Javed Ansari (http://www.bigapplesharepoint.com/team?showExpertName=Javed%20Ansari&rsource=pgblog), sau tau ib cov ncej luv xaus blog rau coj nws nyiam los kawg twb tau siv cov nrog SharePoint: http://www.bigapplesharepoint.com/pages/View-An-Insight.aspx?BlogID=53&rsource=PGBlog).

jQuery nkawd tau victor cov nyob teb, li ntawd, yuav hais lus, xyoo tam sim no, tiam sis yog lwm tus tshiab ntxiv thiab stills txog battling nws txheeb, zoo li Angular. (SPServices, tau mas, tau ib lub neej saver xyoo thiab tseem yuav raug ces kuv xav tias).

Dab tsi yog cov neeg uas siv? Yog lawv teem dua rau hauv Microsoft lub tooling (CSOM / JSOM) los yog tsiv ntxiv mus rau Angular, Knockout, Ember, yam?

Kuv muaj ib tug thuam pheej loj mus rau tej kev coj tsis yog Microsoft lub. Kuv xav tias tus MSFT khoom yog nyuab nyuab zog ua hauj lwm nrog, kheej yuav luag npaum kev nkhaus li laus-style neeg rau zaub mov ces dev.

Logged nov los dhau ntawm Loj lub kua SharePoint Yog koj xav tham txog (Kua ntau yuav tau ntxiv yuav ua rau muaj kev sib sab laj zoo).

</kawg>

Overcome Annoying teeb meem nrog tus kwv tij Urls hauv SharePoint ceev Launch

Kuv xav mus ntxiv ib qhov txuas rau tus ceev community launch navigation lwm hnub thiab SharePoint hais rau kuv:

image

Ntawv ntshiab version ntawd yog:

Xyuas kom qhov URL no siv tau pib nrog tog twg los ib tug cim uas koj siv tau (ib daim ntawv tooj (#) los luaj pem (/)) los yog ib tug siv tau txaus siab raws tu qauv (Piv txwv, ' http://’, ' https://’, ' ntaub ntawv://’, ' ftp://’, ' mailto:’, ' xov xwm:’).

"Blech thiab qoob!"Kuv hais.

Ib lub workaround rau qhov no yog siv cov JavaScript nrhiav ib qhov txuas paub tias nyob rau lub lub community launch ceev thiab override cov cwj pwm.

Sim no, ntxiv ib qhov txuas tshiab ntawd rau koj lub chaw kuaj thusly:

image

Kuv siv jQuery. Yuav kom daws tau nws, tau ib co JavaScript thiab jQuery mus rau ntawm nplooj ntawv uas siv cov txheej txheem yuav nyiam koj thiab nrog rau ib txoj kab kev cai zoo li no:

 

$(daim ntawv).npaj txhij( muaj nuj nqi () {

    $("ib tug:muaj('Kuaj URL hloov')").nyem(muaj nuj nqi () { alert("nias hloov tus cwj pwm!"); rov qab los tsis tseeb;});

});

Thiab Bob ntawv koj tus txiv ntxawm.

Cov jQuery selector pom txhua txhua <ib tug> lossis tau "Tshuaj ntsuam URL hloov" nws lub npe. Koj yuav tau xyuas-qhib uas nyob ntawm seb koj txuas thiab xws li.

Lub .click(muaj nuj nqi() xijpeem SharePoint yuav tau ua li cas thaum tus neeg siv clicked overrides. Xyuas kom tseeb tias koj "rov qab mus cuav" los yog mus yos nws yuav ua koj cov khoom thiab ces txhob href qhov dhau, Nws yog ib qho yuav luag yeej tsis koj lub hom phiaj no.

Qhov no yog ua li cas thiab kuaj hauv ib SharePoint hauv Internet chaw, tab sis yuav tsum ua hauj lwm zoo ua 2010 thiab dhau hwv.

</kawg>

undefinedSubscribe rau kuv blog.

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

Tus txiv neej tsis tus Caching hauv JavaScript

[TL;DR version: siv cov ncuav qab zib kom cia ntsuam async hu; kav soj ntsuam lawm hais lus async tam sim ntawd thiab ces validate lawv tom qab nplooj load.]

Kuv twb tau ua rau ntawm qhov chaw intranet SharePoint rau ib tug neeg ntawd nta, cov lwm yam, ib stylized lwm yam navigation uas los ntawm kev xaiv zaub mov muaj tswj ntawm ib txwm qub kev cai sau.  Tsab cai idea yog tias tus neeg twg thiaj tau tus tswj "lawv" rau cov zaub mov uas tsis rau los muab cuam tshuam los ntawm lub ntiaj teb no navigation muab tso los ntawm nws.

(muaj dab tsi subversive incredibly txog ntxiv ib CEWP uas cov ntsiab lus rau ib tug HTML uas loads ib co CSS thiab JS fundamentally tshwm sim yuav luag txhua yam hais txog tus kawm li cwjpwm... tiam sis yog rau lwm tus ncej)

Qhov chaws kom yooj yim yuav zoo nkauj no:

  • Tos li cov nplooj ntawv kom tag rau nraum chaw thau khoom thiab muab ib tug async hu mus thauj tuaj tshuab raj ua ib yam khoom ntawm ib daim ntawv teev tas los yog lists.asmx los yog los xijpeem
  • Siv jQuery, dynamically populate ib Rev yog <lis>tus hauv ib tug niam txiv <ul> (saib cov Christian Pinder tsab xov xwm no rau lub vaj no tecnnique simplistic)
  • Kev siv CSS yuav ua txhua yam rau formatting
  • Nyiaj!

Tej teev hauv no mob ntawd yog txhua zaus thaum leej twg hits yog ib cov chaw nplooj, tus neeg ntawd lub web browser yog caw kom tau yam khoom los ntawm daim ntawv.  Thaum dev no tiav thiab kuaj tau proven yam yuav ruaj thiab teb, no hu no hu ruaj dua 99% lub sij hawm thaum cov zaub mov tsis tshua hloov.  Nws kuj muaj ib tug weird UI muaj uas muaj nyob rau qhov brave new world ntawm cus-ajaxy web sites – cov phab renders thiab xwb ces yog cov ntawv qhia zaub mov kav.  Nws yog jittery thiab distracting rau kuv saib.  Thiab jittery. Li ntawd, caching. 

Kuv raug kho qhov logic thusly:

  • Nrhiav ib cov kua nplaum uas nyob rau hauv qhov browser uas muaj daim ntawv qhia zaub mov li kuv kawg nyeem nws
    • Yog nrhiav tau, kav nws tam sim ntawd.  Tsis txhob tos txog rau sab mus tag rau nraum chaw thau khoom.  (Koj yuav tau xyuas kom tseeb tias koj cov HTML leeg muab tso ntawm no, tab sis nws yuav tsis ua zog).
  • Tos li cov nplooj ntawv kom tag rau nraum chaw thau khoom thiab muab ib tug async hu mus thauj tuaj tshuab raj ua ib yam khoom ntawm ib daim ntawv teev tas los yog lists.asmx los yog los xijpeem
  • Piv li kuv tau tiv cov kua nplaum uas
    • Yog hais tias nws qhov khoom, TSO TSEG
    • Txwv tsis pub, siv jQuery, dynamically populate ib Rev yog <lis>cov nyob hauv lub <ul>
  • Kev siv CSS yuav ua txhua yam rau formatting
  • Nyiaj!

Qee yam uas koj yuav hais, "hav! yog tsis muaj real caching mus rau hauv no vim muaj koj nyob nraum nyeem cov ntawv qhia zaub mov rau nkawv noj txhua txhua zaug uas koj nkaus xwb.”  Thiab koj nyob nraum txoj kev-kuv tsis muab rau tus neeg rau zaub mov ntais txhua yam.  Tab sis vim hu yog async thiab tshwm sim tom qab uas pib ntawm nplooj ntawv HTML payload siab renders, nws "yim" noog kom tus neeg siv.  Daim ntawv qhia zaub mov renders zoo nkauj ntau li cov nplooj draws.  Yog hais tias cov zaub mov zoo li yuav hloov, cov neeg siv yog nyuam ib jittery rov kos ntawm cov ntawv qhia zaub mov, tab sis lub caij ntawd xwb.

Yog cov kev ua no caching zoo tshaj thiab pab kom paub cov neeg rau zaub mov txhij:

  • Muab tso rau hauv ib txoj cai tias tus tus "kua nplaum uas cache" yog muaj tsawg kawg yog 24 teev los yog ib txhia timeframe. Tsuav yog tsis DRA cov kua nplaum uas, siv cov kua nplaum uas tshuab raj snapshot thiab tsis txhob ntaus cov neeg rau zaub mov.

Qhov tshij... uas txhua yam uas tuaj siab tamsim no :). 

Yog leej twg muaj tus muaj cov tswv yim ntse nov kuv yuav hlub kom paub tias lawv.

Thiab ntsig – cov txheej txheem no yuav raug siv rau lwm yam khoom.  No neeg sab muaj ntau yam ntaub ntawv-uas tau tsav ntawv teev rau phab ntau, muaj coob leej kuj tsis tshua hloov (zoo li ib zaug ib lub lim tiam los sis ib hlis ib zaug).  Yog tias koj phiaj txog tej chaw functionality, koj muab tau ib daim UI feem ntau yog rub cov ntsiab lus los ntawm cov kua nplaum uas nyob tom khw thiab rendering tam sim ntawd.  Nws yim sai rau cov neeg siv txawm hais tias koj nyob nraum tsis txuag cov neeg rau zaub mov twg Pest.  Koj tau txuag cov neeg rau zaub mov mus los ntawm kev txiav txim siab rau tej mob uas muaj tej yam rau invalidate no qhov chaw cov kua nplaum uas cache.  Li no tag situational thiab artsy khoom thiab tiag tiag mas kev lom zem :). 

</kawg>

undefinedSubscribe rau kuv blog.

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