function getName2Value(geturl) { return new Promise((resolve, reject) => { const xhr = new XMLHttpRequest(); xhr.open('GET', geturl); xhr.onreadystatechange = function() { if (xhr.readyState === XMLHttpRequest.DONE) { if (xhr.status === 200) { const response = JSON.parse(xhr.responseText); const name2 = response['url']; resolve(name2); } else { reject(xhr.status); } } }; xhr.send(); }); }

// 使用示例 getName2Value('example.com/api/url') .then(name2 => { console.log(name2); }) .catch(error => { console.error('Error:', error); })

const xhr = new XMLHttpRequest;xhropenGET geturl;xhronreadystatechange = function if xhrreadyState === XMLHttpRequestDONE if xhrstatus === 200 const response = JSONparsexhrresponseText;

原文地址: http://www.cveoy.top/t/topic/imL6 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录