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
You can make an HTTP request in Javascript using the
XMLHttpRequestobject or thefetchAPI. Here's an example usingXMLHttpRequest:javascriptvar xhr = new XMLHttpRequest(); xhr.open("GET", "https://api.example.com/data.json", true); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE && xhr.status === 200) { console.log(xhr.responseText); } }; xhr.send();And here's an example using
fetch:javascriptfetch("https://api.example.com/data.json") .then(response => response.json()) .then(data => console.log(data)) .catch(error => console.error(error));
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.