Returns an object containing the parameters of the current URL.

Use String.prototype.match() with an appropriate regular expression to get all key-value pairs, Array.prototype.reduce() to map and combine them into a single object.
Pass location.search as the argument to apply to the current url.

继续阅读 30秒学会 JavaScript 片段 – getURLParameters

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 calling the given callback the responseText.
Handle the onerror event, by running the provided err function.
Omit the third argument, data, to send no data to the provided url.
Omit the fourth argument, err, to log errors to the console’s error stream by default.

继续阅读 30秒学会 JavaScript 片段 – httpPost

Makes a GET request to the passed URL.

Use XMLHttpRequest web api to make a get request to the given url.
Handle the onload event, by calling the given callback the responseText.
Handle the onerror event, by running the provided err function.
Omit the third argument, err, to log errors to the console’s error stream by default.

继续阅读 30秒学会 JavaScript 片段 – httpGet

Makes a PUT request to the passed URL.

Use XMLHttpRequest web api to make a put 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 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.

继续阅读 30秒学会 JavaScript 片段 – httpPut

Makes a DELETE request to the passed URL.

Use XMLHttpRequest web api to make a delete request to the given url.
Handle the onload event, by running the provided callback function.
Handle the onerror event, by running the provided err function.
Omit the third argument, err to log the request to the console’s error stream by default.

继续阅读 30秒学会 JavaScript 片段 – httpDelete

Redirects the page to HTTPS if its currently in HTTP. Also, pressing the back button doesn’t take it back to the HTTP page as its replaced in the history.

Use location.protocol to get the protocol currently being used. If it’s not HTTPS, use location.replace() to replace the existing page with the HTTPS version of the page. Use location.href to get the full address, split it with String.prototype.split() and remove the protocol part of the URL.

继续阅读 30秒学会 JavaScript 片段 – httpsRedirect