responseText - XMLHttpRequest

responseText - XMLHttpRequest(responseText - XMLHttpRequest)
本文介绍了responseText - XMLHttpRequest的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

限时送ChatGPT账号..

在我的代码中 responseText 不起作用.它应该显示,在文本框中输入的文本+:您的请求已被 syam 看到"

<html><head id="Head1" runat="server"><标题></标题><脚本类型="文本/javascript">var xmlHttpRequest;函数 sSignature(str) {xmlHttpRequest = 新的 XMLHttpRequest();xmlHttpRequest.onreadystatechange = function() {如果(xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200){document.getElementById("target").innerHTML = xmlHttpRequest.responseText;}}xmlHttpRequest.open("GET", "AjaxResponse.aspx?q=" + str, true);xmlHttpRequest.send();}</脚本></头><身体><form id="form1" runat="server">

输入一个字符串:<input type="text" id="textbox" onkeyup="sSignature(this.value)"/><span id="target">这里的文字应该改变</span></div></表格></身体></html>

在代码隐藏页面中,在 page_load() 中

string sRequest = Request.QueryString["q"];var sResponse = sRequest+ " :您的请求已被 syam 看到";Response.Write(sResponse);

解决方案

我相信错误出在您的 onreadystatechangedhandler 中.它将接收一个 event 参数,其中 target 属性指向 XHR 实例.

尝试用这个换掉它:

xmlHttpRequest.onreadystatechange = 函数(事件){var xhr = event.target;如果(xhr.readyState === 4 && xhr.status === 200){document.getElementById("target").innerHTML = xhr.responseText}};

in my code responseText is not working. It is supposed to display, text entered in the text box +" :Your request has been seen by syam"

<html>
    <head id="Head1" runat="server">
    <title></title>
        <script type="text/javascript">
            var xmlHttpRequest;
            function sSignature(str) {

                xmlHttpRequest = new XMLHttpRequest();
                xmlHttpRequest.onreadystatechange = function() {
                    if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {                
                        document.getElementById("target").innerHTML =    xmlHttpRequest.responseText;
                    }
                }
                xmlHttpRequest.open("GET", "AjaxResponse.aspx?q=" + str, true);
                xmlHttpRequest.send();
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
            enter a string :<input type="text" id="textbox" onkeyup="sSignature(this.value)"/>
            <span id="target">text should change here</span>
            </div>
        </form>
    </body>
</html> 

In the code-behind page, in page_load()

string sRequest = Request.QueryString["q"];
var sResponse = sRequest+ " :Your request has been seen by syam";
Response.Write(sResponse);

解决方案

I believe the error is in your onreadystatechangedhandler. It will receive an event param, in which the target property points to the XHR-instance.

Try swapping it out with this:

xmlHttpRequest.onreadystatechange = function (event) {
    var xhr = event.target;

    if (xhr.readyState === 4 && xhr.status === 200) {
        document.getElementById("target").innerHTML = xhr.responseText
    }
};

这篇关于responseText - XMLHttpRequest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

SCRIPT5: Access is denied in IE9 on xmlhttprequest(SCRIPT5:在 IE9 中对 xmlhttprequest 的访问被拒绝)
XMLHttpRequest module not defined/found(XMLHttpRequest 模块未定义/未找到)
Show a progress bar for downloading files using XHR2/AJAX(显示使用 XHR2/AJAX 下载文件的进度条)
How can I open a JSON file in JavaScript without jQuery?(如何在没有 jQuery 的情况下在 JavaScript 中打开 JSON 文件?)
How do I get the HTTP status code with jQuery?(如何使用 jQuery 获取 HTTP 状态码?)
quot;Origin null is not allowed by Access-Control-Allow-Originquot; in Chrome. Why?(“Access-Control-Allow-Origin 不允许 Origin null在铬.为什么?)