问题描述
我的Javascript函数请求到aspx页面。 $ b $bİts代码:
My Javascript function request to a aspx page.İts Code:
var xhr = ("XMLHttpRequest" in window) ? new XMLHttpRequest() : new ActiveXObject("Msxml3.XMLHTTP");
xhr.open("GET", = 'http://www.example.net/abc.aspx', true);
xhr.send("");
在此请求之后,我想从此页面发回一个响应并在客户端捕获它。我该怎么做?
After this request I want to send a response back from this page and catch it on the client side. How do I do that?
推荐答案
从获取响应XMLHttpRequest
在异步模式下(第三个参数 true
open()
方法)你必须设置 onreadystatechange
属性为回调函数。当在浏览器上准备好响应时,将回调此函数:
To get the response from XMLHttpRequest
in asynchronous mode (third parameter is true
for the open()
method) you have to set the onreadystatechange
property to a callback function. This function will be called back when the response is ready at the browser:
xhr.open("GET", 'http://www.example.net/abc.aspx', true);
xhr.onreadystatechange = function() {
if (xhr.readyState === 4) {
var serverResponse = xhr.responseText;
}
};
xhr.send(null);
您可能需要查看以下文章以进一步阅读该主题:
You may want to check out the following article for further reading on the topic:
- AJAX Patterns: XMLHttpRequest Call
这篇关于在Javascript请求后使用Javascript从服务器获取响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!