标签: readystate

XMLHttpRequest中的不同readystates是什么意思,我该如何使用它们?

XMLHttpRequest有5 readyState秒,我只使用其中的1个(最后一个4).

有什么其他用途,我可以使用哪些实际应用?

javascript ajax xmlhttprequest readystate

112
推荐指数
3
解决办法
11万
查看次数

如何检测是否触发了DOMContentLoaded

我正在尝试帮助开发一个库,为此我正在尝试使用页面加载.
在这个过程中,我想让库完全兼容defer和async的使用.

我想要的很简单:
我怎么知道DOMContentLoaded在文件执行时被触发了?

为什么这么难?
在IE中,document.readyState在DOMContentLoaded之前显示交互.
不会以任何方式使用浏览器检测,这违反了我和其他参与者的政策.

什么是正确的选择?

编辑:

好像我还不够清楚.我没有兴趣知道是否已经发生加载事件!我已经知道如何解决这个问题!我想知道如何用DOMContentLoaded解决!!!

javascript events readystate

45
推荐指数
3
解决办法
3万
查看次数

Ajax不会超过readyState 1,为什么?

我正在尝试让这个函数工作,这对请求参数url然后发送callback一个函数的responseText .

它似乎只能到达readyState 1(感谢Firebug命令).

这里是:

function Request(url, callback){
if (window.XMLHttpRequest) { // Mozilla, Safari, ...
    httpRequest = new XMLHttpRequest();
} else if (window.ActiveXObject) { // IE
    httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
} else{
    return false;
}
httpRequest.onreadystatechange = function(){
    console.log(httpRequest.readyState);
    if (httpRequest.readyState == 4) {
        callback(httpRequest.responseText);
    }
};
console.log(httpRequest, url);
httpRequest.open('GET', url, true);
httpRequest.send(null);
}
Run Code Online (Sandbox Code Playgroud)

javascript ajax readystate

11
推荐指数
1
解决办法
5万
查看次数

方法POST,状态(已取消)错误消息

我有以下代码,它给我一个Method POST, Status (canceled)错误消息:

$(document).ready(function() {
    var xhr = false;

    get_default();

    $('#txt1').keyup( function() {
        if(xhr && xhr.readyState != 4){
            alert("abort");
            xhr.abort();
        }

        if ($("#txt1").val().length >= 2) {
            get_data( $("#txt1").val() );
        } else {
            get_default();
        }
    });

    function get_data( phrase ) {
        xhr = $.ajax({
            type: 'POST',
            url: 'http://intranet/webservices.asmx/GetData',
            data: '{phrase: "' + phrase + '"}',
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function( results ) {
                $("#div1").empty();

                if( results.d[0] ) {
                    $.each( results.d, function( index, result ) {
                        $("#div1").append( …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery readystate

11
推荐指数
1
解决办法
2万
查看次数

动态创建脚本:readyState永远不会"完成"

我试图在脚本完全加载后做一些事情.(IE8)

我用于测试的脚本:http://ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.min.js
和无效的脚本:http://ajax.googleapis.com/ajax/libs/的jquery/1.5.1/jquery.minaaaaaaaa.js

代码...

var script = create the element and append to head...

// this works fine with FF/Chrome/...
script.onload = function() {alert('script loading complete');}
script.onerror = function() {alert('error loading script');}

// and for IE
script.onreadystatechange = function() {
    // this will alert 1.loading 2.loaded
    alert(this.readyState);

    // this never works
    if(this.readyState == 'complete') {alert('script loading complete');}

    // this works with either a valid or INVALID url
    else if(this.readyState == 'loaded') {alert('script loaded');}
}; …
Run Code Online (Sandbox Code Playgroud)

javascript readystate onreadystatechange

10
推荐指数
2
解决办法
1万
查看次数

jQuery $ .ajax和readyStates

如何在jQuery $.ajax方法上调用Ajax就绪状态?

ajax jquery readystate onreadystatechange

8
推荐指数
2
解决办法
3万
查看次数

如果readystate = 4且status = 200,则执行Jquery S.Ajax错误处理程序

我正在进行$ .ajax调用,它返回一个json响应,一切似乎都很好,但是调用成功处理程序,即使readystate = 4和status = 200,也会调用$ .ajax错误处理程序.

$ .ajax电话是: -

    $.ajax({
        url: 'inc/ajax_printorder.asp',
        type: "GET",
        data: data,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        cache: false,
        success: function (sendresponse) {
            var message = (typeof sendresponse.jsonresp) == 'string' ? eval('(' + sendresponse.jsonresp + ')') : sendresponse.jsonresp;
            if (message[0].ok == '1') {
                var order = window.open('', 'PrintWindow', 'width=600,height=600');
                var html = '<html><head><title>Print Your Order</title></head><body><div id="myprintorder">' + $('<div />').append(message[0].msg) + '</div></body></html>';
                order.document.open();
                order.document.write(html);
                order.document.close();
                return false;
            };
        },
        error: function (xhr, err) {
            alert("readyState: " …
Run Code Online (Sandbox Code Playgroud)

ajax jquery status readystate

7
推荐指数
1
解决办法
1万
查看次数

Failproof等待IE加载

是否有一种万无一失的方式让脚本等到Internet Explorer完全加载?

两者oIE.Busy和/或oIE.ReadyState都没有按照他们应该的方式工作:

Set oIE = CreateObject("InternetExplorer.application")

    oIE.Visible = True
    oIE.navigate ("http://technopedia.com")

    Do While oIE.Busy Or oIE.ReadyState <> 4: WScript.Sleep 100: Loop  

    ' <<<<< OR >>>>>>

    Do While oIE.ReadyState <> 4: WScript.Sleep 100: Loop
Run Code Online (Sandbox Code Playgroud)

还有其他建议吗?

vbscript internet-explorer wsh readystate web-scraping

7
推荐指数
1
解决办法
5万
查看次数

在 LAN 上部署 R 闪亮应用程序:未捕获类型错误:无法读取 null 的属性“readyState”

我已经构建了一个闪亮的网络应用程序,我想与我的同事分享。

我使用的其中runApp(host = getOption("shiny.host", "10.161.112.8"))10.161.112.8 是我的主机服务器 IP 地址。

该应用程序在我的本地服务器上完美运行,但某些远程客户端(不是全部!)直接显示灰屏(或最多 1 秒后)。在检查他们的网页源代码时,我收到以下错误:

Uncaught TypeError: Cannot read property 'readyState' of null
    at ShinyApp.$sendMsg (shinyapp.js:288)
    at ShinyApp.sendInput (shinyapp.js:140)
    at InputBatchSender.$sendNow (input_rate.js:220)
Run Code Online (Sandbox Code Playgroud)

在这里红色它可能与网络套接字限制有关。但我没有找到任何适合我的解决方案......

有人有什么建议吗?任何帮助将非常感激!

r readystate shiny shinyjs shinyapps

7
推荐指数
0
解决办法
1515
查看次数

request.xhr在Ext JS中未定义

我的网站是使用Ext JS 4.1框架和ASP .Net MVC v3制作的.呈现新帧时,有19个单独的AJAX请求用于以JSON格式检索数据.所有请求都是Ext.Ajax.request()所熟悉的.例:

Ext.Ajax.request({
    url: getOrderLink,
    method: "GET",
    params: { recId: orderRecId },
    headers: {
        'Accept': 'application/json'
    },
    success: function (response) {
        var order = Ext.decode(response.responseText);
        ...
    }
});
Run Code Online (Sandbox Code Playgroud)

在某些情况下,ext-all.js中存在错误

onStateChange : function(request) {
    if (request.xhr.readyState == 4) {
        this.clearTimeout(request);
        this.onComplete(request);
        this.cleanup(request);
    }
},
Run Code Online (Sandbox Code Playgroud)

请求没有属性xhr,以便request.xhr.readyState抛出异常"无法读取未定义的属性'readState'".此错误不会出现在所有请求中,也不会影响站点工作(成功检索响应).有时这些错误根本不会出现.默认情况下,所有请求的超时设置为30秒,每个请求大约需要1.5-2秒.我正在使用谷歌浏览器21.你能不能告诉我为什么会这样.

ajax xmlhttprequest readystate extjs4.1

6
推荐指数
1
解决办法
2055
查看次数