update tag_database, update httpPost
This commit is contained in:
@ -4,16 +4,15 @@ Makes a `POST` request to the passed URL.
|
|||||||
|
|
||||||
Use `XMLHttpRequest` web api to make a `post` request to the given `url`.
|
Use `XMLHttpRequest` web api to make a `post` request to the given `url`.
|
||||||
Set the value of an `HTTP` request header with `setRequestHeader` method.
|
Set the value of an `HTTP` request header with `setRequestHeader` method.
|
||||||
Handle the `onload` event, by running the provided `callback` function.
|
Handle the `onload` event, by console logging the `responseText`.
|
||||||
Handle the `onerror` event, by running the provided `err` function.
|
Handle the `onerror` event, by running the provided `err` function.
|
||||||
Omit the last argument, `err` to log the request to the console's error stream by default.
|
|
||||||
|
|
||||||
```js
|
```js
|
||||||
const httpPost = (url, data, callback, err = console.error) => {
|
const httpPost = (url, data, err = console.error) => {
|
||||||
const request = new XMLHttpRequest();
|
const request = new XMLHttpRequest();
|
||||||
request.open("POST", url, true);
|
request.open("POST", url, true);
|
||||||
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||||
request.onload = () => callback(request);
|
request.onload = () => console.log(request.responseText);
|
||||||
request.onerror = () => err(request);
|
request.onerror = () => err(request);
|
||||||
request.send(data);
|
request.send(data);
|
||||||
};
|
};
|
||||||
@ -27,5 +26,5 @@ const user = {
|
|||||||
const data = JSON.stringify(user);
|
const data = JSON.stringify(user);
|
||||||
httpPost('https://website.com/posts', data, request => {
|
httpPost('https://website.com/posts', data, request => {
|
||||||
console.log(request.responseText);
|
console.log(request.responseText);
|
||||||
}); // 'Makes a new instance of user in database'
|
}); // ''
|
||||||
```
|
```
|
||||||
|
|||||||
@ -61,10 +61,8 @@ hasFlags:node
|
|||||||
head:array
|
head:array
|
||||||
hexToRGB:utility,string,math,advanced
|
hexToRGB:utility,string,math,advanced
|
||||||
hide:browser,css
|
hide:browser,css
|
||||||
httpDelete:utility,url,browser
|
|
||||||
httpGet:utility,url,browser
|
httpGet:utility,url,browser
|
||||||
httpPost:utility,url,browser
|
httpPost:utility,url,browser
|
||||||
httpPut:utility,url,browser
|
|
||||||
httpsRedirect:browser,url
|
httpsRedirect:browser,url
|
||||||
indexOfAll:array
|
indexOfAll:array
|
||||||
initial:array
|
initial:array
|
||||||
|
|||||||
Reference in New Issue
Block a user