Skip to content

Instantly share code, notes, and snippets.

@AsishP
Created March 11, 2018 10:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AsishP/b4520209a12c46a492e26dc5ff5423ba to your computer and use it in GitHub Desktop.
Save AsishP/b4520209a12c46a492e26dc5ff5423ba to your computer and use it in GitHub Desktop.
var functionUrl : string = "https://[functionName].azurewebsites.net/api/[FunctionMethod]?code=[codeValue]"
const requestHeaders: Headers = new Headers();
requestHeaders.append("Content-type", "application/json");
requestHeaders.append("Cache-Control", "no-cache");
const postOptions : RequestInit = {
headers: requestHeaders,
body: `{\r\n siteURL: '${siteUrl}',\r\n pageName: '${pageName}' \r\n}`,
method: "POST"
};
let responseText: string = "";
let createPageStatus: string = "";
console.log("Wait started for Creating page");
await fetch(functionUrl, postOptions).then((response) => {
console.log("Response returned");
if (response.ok) {
return response.json()
}
else
{
var errMsg = "Error detected while adding site page. Server response wasn't OK ";
console.log(errMsg);
}
}).then((responseJSON: JSON) => {
responseText = JSON.stringify(responseJSON).trim();
console.log(responseText);
if(responseText.toLowerCase().indexOf("uccess") > 0)
{
console.log("success feedback");
}
if(responseText.toLowerCase().indexOf("rror") > 0)
{
console.log("web call errored");
}
}
).catch ((response: any) => {
let errMsg: string = `WARNING - error when calling URL ${functionUrl}. Error = ${response.message}`;
console.log(errMsg);
});
console.log("wait finished");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment