假设index.html的脚本具有外部js文件的url(example.js):
<html>
<head>
<script src="/example.js"></script>
</head>
<body></body>
</html>
我尝试过它创建XMLHttpRequest,而不是用window.eval(request.responseText)
手动执行脚本。还有其他方法吗?
要在向服务器发出请求时获取响应标头:
香草JS:
var client = new XMLHttpRequest();
client.open("GET", "/some_url", true);
client.send();
client.onreadystatechange = function() {
if (this.readyState == this.HEADERS_RECEIVED) {
console.log(client.getResponseHeader("some_header"));
}
}
jQuery的:
$.ajax({
type: 'GET',
url: '/some_url',
success: function(data, textStatus, request) {
console.log(request.getResponseHeader('some_header'));
},
error: function(request, textStatus, errorThrown) {
console.log(request.getResponseHeader('some_header'));
}
});