Unknown model· unknown
ShareGPT 90K (shared ChatGPT conversations)
How do I make an HTTP request in Javascript?
- User
How do I make an HTTP request in Javascript?
- Assistant
To make an HTTP request in JavaScript, you can use the
XMLHttpRequestobject or the newerfetch()function.Here is an example of making an HTTP GET request using
XMLHttpRequest:codefunction makeRequest() { var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (xhr.readyState == XMLHttpRequest.DONE) { console.log(xhr.responseText); } } xhr.open('GET', 'https://www.example.com/', true); xhr.send(null); }And here is an example using
fetch():codefetch('https://www.example.com/') .then(function(response) { return response.text(); }) .then(function(text) { console.log(text); });Both examples will make an HTTP GET request to the specified URL. The response from the server will be logged to the console.
You can also use
XMLHttpRequestorfetch()to make other types of HTTP requests, such as POST, PUT, DELETE, etc.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.