Encode a set of form elements as a query string.

Use the FormData constructor to convert the HTML form to FormData, Array.from() to convert to an array, passing a map function as the second argument.
Use Array.prototype.map() and window.encodeURIComponent() to encode each field’s value.
Use Array.prototype.join() with appropriate argumens to produce an appropriate query string.

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

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

Triggers a specific event on a given element, optionally passing custom data.

Use new CustomEvent() to create an event from the specified eventType and details.
Use el.dispatchEvent() to trigger the newly created event on the given element.
Omit the third argument, detail, if you do not want to pass custom data to the triggered event.

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

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