我正在使用我在此处找到的示例代码:
http://www.w3schools.com/ajax/tryit.asp?filename=tryajax_post2
我想从需要身份验证的端点获取JSON字符串。
如何通过向端点发出请求来指定我的ID / Pass(是否有可以使用的HTTP标头要求我进行身份验证)?
连接到可能需要我们进行身份验证的网址的解决方法是什么?
如何指定使用SSL证书获取响应?
< script >
function loadDoc() {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("demo").innerHTML = xhttp.responseText;
}
};
xhttp.open("POST", "demo_post2.asp", true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.send("fname=Henry&lname=Ford");
} < /script>