- $.ajax({
- url: url,
- type: method,
- oauth: true,
- data: data,
- success: function () {
- OSM.loadSidebarContent(window.location.pathname, page.load);
- },
- error: function (xhr, xhr_status, http_status) {
- $(form).find("#comment-error").text(http_status);
- $(form).find("#comment-error").prop("hidden", false);
- $(form).find("input[type=submit]").prop("disabled", false);
- }
- });
+ fetch(url, {
+ method: method,
+ headers: { ...OSM.oauth },
+ body: data
+ })
+ .then(response => {
+ if (response.ok) return response;
+ return response.text().then(text => {
+ throw new Error(text);
+ });
+ })
+ .then(() => {
+ OSM.loadSidebarContent(location.pathname, page.load);
+ })
+ .catch(error => {
+ content.find("button[data-method][data-url]").prop("disabled", false);
+ content.find("#comment-error")
+ .text(error.message)
+ .prop("hidden", false)
+ .get(0).scrollIntoView({ block: "nearest" });
+ });