Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cancel Button #11

Closed
appatalks opened this issue Jan 31, 2023 · 1 comment
Closed

Cancel Button #11

appatalks opened this issue Jan 31, 2023 · 1 comment

Comments

@appatalks
Copy link
Owner

I may look into this:

Here's an example of how you could provide a cancel button for the user to interrupt an API request in Javascript and HTML:

HTML:

Cancel Request

JavaScript:

var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://api.example.com/data');

document.getElementById("cancel-btn").addEventListener("click", function() {
xhr.abort();
});

xhr.onreadystatechange = function() {
if (xhr.readyState === XMLHttpRequest.DONE) {
if (xhr.status === 200) {
console.log(xhr.responseText);
}
}
};

xhr.send();

In this example, a GET request is being made using the XMLHttpRequest object. When the user clicks the "Cancel Request" button, the xhr.abort() method is called to interrupt the request. When the response is received, the xhr.readyState property is checked to see if the request has completed, and the xhr.status property is checked to see if the response was successful (status code 200). If the request was successful, the response text is logged to the console.

@appatalks
Copy link
Owner Author

I don't really see a need for this anymore. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant