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 thefetch()function.Here's an example using
XMLHttpRequest:var xhr = new XMLHttpRequest(); xhr.open('GET', 'https://www.example.com/', true); xhr.onload = function () { if (this.status == 200) { // Success - do something with the response console.log(this.responseText); } else { // Error - handle the error } }; xhr.send();And here's an example using
fetch():fetch('https://www.example.com/') .then(function (response) { // Success - do something with the response console.log(response); }) .catch(function (error) { // Error - handle the error });Both of these examples make a
GETrequest to the specified URL. You can also use theopen()method and thesend()method to make other types of requests, such asPOST,PUT, andDELETE.Hope this helps! Let me know if you have any other questions.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.