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`.
|
||||
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.
|
||||
Omit the last argument, `err` to log the request to the console's error stream by default.
|
||||
|
||||
```js
|
||||
const httpPost = (url, data, callback, err = console.error) => {
|
||||
const httpPost = (url, data, err = console.error) => {
|
||||
const request = new XMLHttpRequest();
|
||||
request.open("POST", url, true);
|
||||
request.setRequestHeader('Content-type','application/json; charset=utf-8');
|
||||
request.onload = () => callback(request);
|
||||
request.onload = () => console.log(request.responseText);
|
||||
request.onerror = () => err(request);
|
||||
request.send(data);
|
||||
};
|
||||
@ -27,5 +26,5 @@ const user = {
|
||||
const data = JSON.stringify(user);
|
||||
httpPost('https://website.com/posts', data, request => {
|
||||
console.log(request.responseText);
|
||||
}); // 'Makes a new instance of user in database'
|
||||
}); // ''
|
||||
```
|
||||
|
||||
@ -61,10 +61,8 @@ hasFlags:node
|
||||
head:array
|
||||
hexToRGB:utility,string,math,advanced
|
||||
hide:browser,css
|
||||
httpDelete:utility,url,browser
|
||||
httpGet:utility,url,browser
|
||||
httpPost:utility,url,browser
|
||||
httpPut:utility,url,browser
|
||||
httpsRedirect:browser,url
|
||||
indexOfAll:array
|
||||
initial:array
|
||||
|
||||
Reference in New Issue
Block a user