Txoj kev sai thiab yooj yim: Ua kom muaj ib qhov chaw SharePoint siv so

Muaj ntau ntau pab ib ncig uas qhia tau tias yuav ua li cas, tab sis kuv nrhiav tsis tau ib tug muab mus-mus txuas, yog li no peb cov.

Koj muaj peev xwm tsim ib qhov chaw SharePoint siv API so.  Ntawm no yog ib tug piv txwv ci siab:

<!--
    SiteRequestForm.html: Sau xov xwm thiab tsim tau ib qhov chaw rau cov neeg siv.
-->

<chaw>
<cov lus>
    <tr>
        <Td>Rau npe:</Td>
        <Td><tswv yim hom= "ntawv nyeem" lub npe= "SiteName" tus ID= "SiteName" /></Td>
    </tr>
    <tr>
        <Td colspan= "2">
            <tswv yim hom= "xa ntawv" tus ID= "CreateSiteButton" tus nqi= "Tsim lub Site" />
        </Td>
    </tr>
</cov lus>
</chaw>

<tsab ntawv src="../Plugins/jquery-1.11.0.min.js"></tsab ntawv>

<tsab ntawv>
Var CreateSiteLogicContainer = {

    createSiteData: {
            "tsis": {
                __metadata: { "hom": "SP.WebInfoCreationInformation" },
                Url: "Paultest1",
                Npe: "Paultest1",
                Hauj lwm lawm: "tsim so web los ntawm Paul!",
                Hais lus: 1033,
                WebTemplate: "sts",
                UseUniquePermissions: tsis tseeb
            }
    },

    createSite: muaj nuj nqi () {

        jQuery.support.cors = tseeb;

        CreateSiteLogicContainer.createSiteData.parameters.Url = $("#SiteName").val();
        
        $.ajax({
            url: "https://bigapplesharepoint.sharepoint.com/NBAIADev/_api/web/webinfos/add",
            txujci: "NCEJ",

            headers: {
                "Txais": "daim ntawv thov/json; odata = verbose",
                "cov ntawv hom": "daim ntawv thov/json;odata = verbose",
                "X-RequestDigest": $("#__REQUESTDIGEST").val()
            },

            cov ntaub ntawv: JSON.stringify(CreateSiteLogicContainer.createSiteData),

            zoo: muaj nuj nqi () { alert("zoo"); },
            yuam kev: muaj nuj nqi () { alert("kev ua yuam kev"); }

        });
    },

    wireUpForm: muaj nuj nqi () {
        $("#CreateSiteButton").nyem(muaj nuj nqi () {
            alert("Li mus sim thiab tsim tau lub site.");
            CreateSiteLogicContainer.createSite();
        });
    }


}

CreateSiteLogicContainer.wireUpForm();

</tsab ntawv>

Thaum zoo, koj tau ib tug JSON tuaj rau lawv teb li no:

image

Kuv xav tseem ceeb thiab learnings ntawm no muaj xws li:

  • Kauj siv jQuery.  Hauv kuv tsev neeg, Kuv lub tsev qiv ntawv jQuery nyob rau hauv "../ plugins. "  Koj mam li xav hais tias yuav kis tau mus rau qhov chaw koj nyiam JQ nyob.
  • Luam thiab paste ntawd cov snippet tag nrho rau hauv ib cov ntawv Editor Web feem ntawm ib sab thiab nws yuav tsum ua hauj lwm xwb fine.  Koj mam xav hloov tag kis API hu thiab xyuas kom tseeb tias koj siv JQ kom raug.
  • Qhov URL yog ntu koj API endpoint.  Hauv kuv tsev neeg, Nws yog ib txoj kev kom ncua chaw kom https://bigapplesharepoint.com
  • Koj tsis tas yuav muab cov ntsiab lus-ntev. Ib co posts uas nyuam thiab MSDN daim ntawv implies tias koj tsis, tab sis tshwm sim rau kuv tau, uas kuv xav tias yog raug leej twg rau $.ajax hu rau nws tus kheej.
  • Cov kab no yuav tsum tau kom tsis txhob muaj qhov lus teb "forbidden": "X-RequestDigest": $("#__REQUESTDIGEST").val().  Muaj ntau hom kev ua, tab sis qhov no yog qhov zoo zoo nkauj.  Kuv tau poob qhov link rau blog muab no shortcut.  H/T rau koj, mysterious blogger!

Hmoov zoo thiab vam cia qhov no yuav pab lwm tus neeg paub.

</kawg>

undefinedSubscribe rau kuv blog.

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

sau ntawv cia

Koj email chaw nyob yuav tsis muab luam tawm. Search cim *