XMLHttpRequest有5 readyState秒,我只使用其中的1个(最后一个4).
有什么其他用途,我可以使用哪些实际应用?
我正在尝试帮助开发一个库,为此我正在尝试使用页面加载.
在这个过程中,我想让库完全兼容defer和async的使用.
我想要的很简单:
我怎么知道DOMContentLoaded在文件执行时被触发了?
为什么这么难?
在IE中,document.readyState在DOMContentLoaded之前显示交互.
我不会以任何方式使用浏览器检测,这违反了我和其他参与者的政策.
什么是正确的选择?
编辑:
好像我还不够清楚.我没有兴趣知道是否已经发生加载事件!我已经知道如何解决这个问题!我想知道如何用DOMContentLoaded解决!!!
我正在尝试让这个函数工作,这对请求参数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) 我有以下代码,它给我一个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) 我试图在脚本完全加载后做一些事情.(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) 如何在jQuery $.ajax方法上调用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) 是否有一种万无一失的方式让脚本等到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)
还有其他建议吗?
我已经构建了一个闪亮的网络应用程序,我想与我的同事分享。
我使用的其中runApp(host = getOption("shiny.host", "10.161.112.8"))10.161.112.8 是我的主机服务器 IP 地址。
该应用程序在我的本地服务器上完美运行,但某些远程客户端(不是全部!)直接显示灰屏(或最多 1 秒后)。在检查他们的网页源代码时,我收到以下错误:
Run Code Online (Sandbox Code Playgroud)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)
我在这里红色它可能与网络套接字限制有关。但我没有找到任何适合我的解决方案......
有人有什么建议吗?任何帮助将非常感激!
我的网站是使用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.你能不能告诉我为什么会这样.
readystate ×10
ajax ×6
javascript ×5
jquery ×3
events ×1
extjs4.1 ×1
r ×1
shiny ×1
shinyapps ×1
shinyjs ×1
status ×1
vbscript ×1
web-scraping ×1
wsh ×1