Created
March 5, 2020 17:54
-
-
Save JamesIgoe/1acb284d59df31c5ebb79a76be1c4cae to your computer and use it in GitHub Desktop.
Variety of POST examples in JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function postMessageXhr() { | |
var xhr = new XMLHttpRequest(); | |
xhr.open("POST", "", true); | |
xhr.setRequestHeader('Content-Type', 'application/json'); | |
xhr.send(JSON.stringify({ | |
ApplicationName: "", | |
ComputerName: "", | |
OperatingSystem: "", | |
UserName: "", | |
LogLevel: "", | |
Message: "" | |
})); | |
} | |
function postMessageAjax() { | |
$.ajaxSetup({ | |
crossDomain: true, | |
xhrFields: { | |
withCredentials: true | |
}, | |
}); | |
$.ajax({ | |
url: '', | |
data: JSON.stringify({ | |
ApplicationName: '', | |
ComputerName: '', | |
OperatingSystem: '', | |
UserName: '', | |
LogLevel: '', | |
Message: '' | |
}), | |
dataType: "json", | |
contentType: 'application/json', | |
type: 'POST', | |
error: function (xhr, status, error) { | |
app.showNotification(_appName, error); | |
} | |
}).done(function (data) { | |
app.showNotification(_appName, data); | |
}); | |
} | |
function postMessageJquery() { | |
$.post("", { | |
ApplicationName: '', | |
ComputerName: '', | |
OperatingSystem: '', | |
UserName: '', | |
LogLevel: '', | |
Message: '' | |
}).done(function (data) { | |
app.showNotification(_appName, data); | |
}).fail(function (xhr, status, error) { | |
app.showNotification(_appName, xhr.statusText); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment