<script> function createXMLHttpRequest() { var xmlHttp; if (window.ActiveXObject) { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } else if (window.XMLHttpRequest) { xmlHttp = new XMLHttpRequest(); } xmlHttp.open("get", "https://merchant-api.jet.com/api/merchant-skus/00-980-001", true); xmlHttp.setRequestHeader("Content-Type", "application/json"); xmlHttp.setRequestHeader("Authorization", "8YrpzzeM56dlCKAlFfdkNMsyGxPgkX844ZxjmASEogWgUMx0bVgAwDDeEjzZUE2W2b9E65DQo"); xmlHttp.send(null); xmlHttp.onreadystatechange = function () { var checkResult = document.getElementById("checkResult"); if (xmlHttp.readyState = 4) { if (xmlHttp.status = 200) { checkResult.innerHTML = xmlHttp.responseText; } else { alert(xmlHttp.statusText); } } }; } function createXMLHttpRequestForPost() { var xmlHttpReq; xmlHttpReq = new XMLHttpRequest(); xmlHttpReq.open("post", "https://merchant-api.jet.com/api/token/", true); xmlHttpReq.setRequestHeader("Content-Type", "application/json"); xmlHttpReq.setRequestHeader("Authorization", "8YrpzzeM56dlCKAlFfdkNMsyGxPgkX844ZxjmASEogWgUMx0bVgAwDDeEjzZUE2W2b9E65DQo"); var content = ‘{"user":"xxxx","pass":"xxxx"}‘; xmlHttpReq.send(content); xmlHttpReq.onreadystatechange = function () { var checkResult = document.getElementById("checkResult"); if (xmlHttpReq.readyState = 4) { if (xmlHttpReq.status = 200) { checkResult.innerHTML = xmlHttpReq.responseText; } else { alert(xmlHttpReq.statusText); } } }; } </script> <p id="checkResult">aaa</p> <button onclick="createXMLHttpRequest()">Call API</button> <button onclick="createXMLHttpRequestForPost()">Call POST API</button>
时间: 2024-10-12 13:54:51