Skip to content

Instantly share code, notes, and snippets.

@topherPedersen
Last active October 29, 2019 09:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save topherPedersen/4e2872ff8b89cc3ee0fb606a1c377e7f to your computer and use it in GitHub Desktop.
That Equals This?
handleRefreshData(paramOne, paramTwo, oldState) {
var that = this;
var httpRequest = new XMLHttpRequest();
var httpRequestURL = "https://mysupersweetdomain.com/my-route";
httpRequest.open("POST", httpRequestURL, true);
httpRequest.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
// Get Response Data
var data = this.responseText;
data = JSON.parse(data);
// Update State With Fresh Financial Data HERE
var newState = oldState;
newState.foo = data.foo;
newState.bar = data.bar;
newState.baz = data.baz;
that.setState(newState); // update state with fresh financial data
}
};
var formData = new FormData();
formData.append("abc", paramOne);
formData.append("xyz", paramTwo);
httpRequest.send(formData);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment