Last active
February 22, 2018 17:08
-
-
Save jonathanlurie/7a6087777b02f98b78c04a157fe6084d to your computer and use it in GitHub Desktop.
Posting to Webtask
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<title>test</title> | |
</head> | |
<body> | |
<div id="output"></div> | |
<script> | |
var output = document.getElementById("output") | |
var baseUrl = 'https://wt-3d8e69c28886f9c9f7ed6ba6797d805b-0.run.webtask.io/simpletest'; | |
var route = "/ping"; | |
var url = baseUrl + route; | |
var dataToSend = { | |
arg1: "A simple string", | |
arg2: 444 | |
} | |
fetch(url, | |
{ | |
method: "POST", | |
headers: { | |
'Accept': 'application/json, text/plain, */*', | |
'Content-Type': 'application/json' | |
}, | |
body: JSON.stringify( dataToSend ) | |
}) | |
.then(function(res){ | |
status = res.status; | |
if( status > 200 ){ | |
throw "Server error, status " + status; | |
return; | |
} | |
return res.json(); | |
}) | |
.then(function(data){ | |
output.innerHTML = JSON.stringify( data ); | |
console.log( data ); | |
}) | |
.catch(function(e){ | |
output.innerHTML = JSON.stringify( {error: 1, message: e} ); | |
console.log( e ); | |
}) | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment