Make XMLHttpRequest synchronous when "async" option is true?

The signature of the open method of XMLHttpRequest looks like this: void open(DOMString method, DOMString url, optional boolean async, optional DOMString? user, optional DOMString? password); The third parameter of open is async . When set to false, the XMLHttpRequest object becomes synchronous, which means it will block the executing process until the request if finished. I was wondering wh

当“异步”选项为真时,使XMLHttpRequest同步?

XMLHttpRequest的open方法的签名如下所示: void open(DOMString method, DOMString url, optional boolean async, optional DOMString? user, optional DOMString? password); open的第三个参数是async 。 当设置为false时,XMLHttpRequest对象变成同步的,这意味着它将阻止正在执行的进程,直到完成请求为止。 我想知道如果async选项设置为true是否可以编写一个(包装)函数getUrlSync(String url) 。 如果是这样,这可

Synchronous XMLHttpRequest is depreciated

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. The purpose of a synchronous XMLHttpRequest ( sxhr ) is it's depreciation that chrome claims. sxhr 's solve problems that otherwise can not be solved using asynchronous calls. Example, the need of a return of a va

同步XMLHttpRequest已折旧

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/. 同步XMLHttpRequest( sxhr )的用途是chrome声称的折旧。 sxhr解决了使用异步调用无法解决的问题。 例如,需要在异步函数外返回一个变量。 异步和同步方法是完全不同的,事实上,它们是相反的; 所以,声称一种方法是用相反的方法折旧

Is it possible to abort a synchronous XmlHttpRequest?

I have written a JavaScript function that asynchronously calls a web service using XmlHttpRequest. I have been asked to make this function finish its work before the page is rendered. I thought I could make the AJAX request synchronous but I don't want this to make the page hang too long - I'd like to abort the request after, say, 1 second if a response isn't received. Is it poss

是否有可能中止同步XmlHttpRequest?

我写了一个JavaScript函数,它使用XmlHttpRequest异步调用Web服务。 我被要求在页面呈现之前让这个功能完成它的工作。 我想我可以使AJAX请求同步,但我不想让这个页面挂起太久 - 如果没有收到响应,我想在1秒后中止请求。 是否有可能中止同步XmlHttpRequest? 你不能: http://www.hunlock.com/blogs/Snippets:_Synchronous_AJAX sais:“同步AJAX(真正的SJAX - 同步Javascript和XML)是模式,这意味着JavaScript将停

How do you make a synchronous / blocking XMLHttpRequest with YUI

There are a number of questions here that ask this but the answers invariably just tell the person they really want an Asynchronous request rather than actually answering the question of how to do a Synchronous request with YUI. I know how to do one with jQuery and when directly manipulating the XMLHttpRequest object but how do you do it when using YUI (without digging through it's guts to f

你如何使用YUI进行同步/阻塞XMLHttpRequest

这里有很多问题要问这个问题,但答案总是告诉他们真正想要异步请求的人,而不是实际回答如何使用YUI执行同步请求的问题。 我知道如何用jQuery做一个,当直接操作XMLHttpRequest对象时,但是如何在使用YUI的时候做到这一点(没有深入挖掘XMLHttpRequest对象,它最终会使用和操纵它)? 在有人问道之前:是的,我知道大部分时间你都希望异步,但有时候同步确实是工作的正确工具。 这是如何在YUI 3中完成的。 我使用YUI 3,

simulating a synchronous XmlHttpRequest

I've read some of the other related questions (Pattern for wrapping an Asynchronous JavaScript function to make it synchronous & Make async event synchronous in JavaScript & there may be more), but I just want to be sure to exhaust all possibilities. Might it be possible to "convert" an asynchronous XmlHttpRequest into a quasi-synchronous one using either setInterval or se

模拟一个同步的XmlHttpRequest

我已经阅读了其他一些相关的问题(包装一个异步JavaScript函数以使其同步并使JavaScript中的异步事件同步,并且可能还有更多),但我只是想确保耗尽所有可能性。 可能使用setInterval或setTimeout将异步XmlHttpRequest“转换”为准同步的XmlHttpRequest? 这个想法是,一旦Ajax请求成功,将设置一个变量,该变量将作为while循环的信号(它已经调用了setInterval或setTimeout,以及适当的回调函数)来退出。 或者我从根本上误

search array of nested objects and return parent if value is found in child

This question already has an answer here: javascript - return parent with only child that matches given search string in array of objects with nested object 2 answers 您可以使用迭代和递归方法并返回检查结果,并在子节点匹配搜索值时构建新的对象和数组。 function getValue(item) { if (Array.isArray(item)) { return item.reduce(iterA, undefined); } if (item && typeof it

搜索嵌套对象的数组,如果在子中找到值,则返回父对象

这个问题在这里已经有了答案: JavaScript - 返回父对象只有与子对象数组中给定的搜索字符串匹配的子对象2个答案 您可以使用迭代和递归方法并返回检查结果,并在子节点匹配搜索值时构建新的对象和数组。 function getValue(item) { if (Array.isArray(item)) { return item.reduce(iterA, undefined); } if (item && typeof item === 'object') { return iterO(item); }

Why won't .filter() work in Internet Explorer 8?

This is the line: songs = songs.filter(function (el) { return el.album==album; }); This is the error: Object doesn't support this property or method This Works 100% fine in Chrome. What's going on? Array.filter() isn't included in IE until version 9. You could use this to implement it: if (!Array.prototype.filter) { Array.prototype.filter = function(fun /*, thisp */)

为什么.filter()不能在Internet Explorer 8中工作?

这是行: songs = songs.filter(function (el) { return el.album==album; }); 这是错误: 对象不支持此属性或方法 这工作在Chrome中100%罚款。 这是怎么回事? 在版本9之前, Array.filter()不包含在IE中。 你可以用它来实现它: if (!Array.prototype.filter) { Array.prototype.filter = function(fun /*, thisp */) { "use strict"; if (this === void 0 || this === null) throw new Ty

Chrome and probably Opera sort object properties automatically

Problem is: Chrome automatically sorts properties of object. If I have an object like: var obj = {4: "first", 2: "second", 1: "third"}; then when I do next: for(var i in obj) { console.debug(obj[i]); } I see next: third second first but expect: first second third Never rely on the order of properties. They are unordered and there is no specification that defines in which order

Chrome和可能Opera自动排序对象属性

问题是:Chrome会自动排序对象的属性。 如果我有像这样的对象: var obj = {4: "first", 2: "second", 1: "third"}; 然后当我做下一个时: for(var i in obj) { console.debug(obj[i]); } 我看到下一个: third second first 但期望: first second third 永远不要依赖于属性的顺序。 它们是无序的,没有规定哪个顺序属性应该枚举。 Chrome使用数字键以数字顺序排列属性,而其他浏览器按插入顺序枚举它们。

Options added to a <select> are invisible in the list box on iPhone

I have an HTML listbox and I'm adding options using javascript - no problems in any browsers on PC - Mozilla, Chrome, IE, Opera, Safari. However, when performed on iPhone the added option is invisible in the listbox -shows only - (0 items) until you tap on the listbox and then you see the added option as if you were tapping on a regular "select" item, tap on it and only after that

添加到<select>的选项在iPhone上的列表框中不可见

我有一个HTML列表框,并且使用javascript添加选项 - 在PC上的任何浏览器都没有问题 - Mozilla,Chrome,IE,Opera,Safari。 但是,在iPhone上执行时,添加的选项在列表框中是不可见的 - 仅显示 - (0项),直到您点击列表框,然后看到添加的选项,就好像您正在点击常规的“选择”项目一样,点击它只有在该选项可见之后。 我希望我已经明白了... 功能如下:用户填充文本框中的文本(tb),单击添加按钮(btn),该选项被创建

Post Ajax function to return true or false

I'm trying to get an Ajax function to return true or false (it's a sort of validation function which is called from another function). So the other function needs to get a true or false value from this one so it would know what to do next This is the function: function validateLogin( uid, pass, i ){ var uvalue = uid.value; var pvalue = pass.value; var xmlhttp

发布Ajax函数返回true或false

我试图让Ajax函数返回true或false(这是一种从另一个函数调用的验证函数)。 所以另一个函数需要从这个函数中得到一个真实或者错误的值,所以它会知道下一步该怎么做 这是功能: function validateLogin( uid, pass, i ){ var uvalue = uid.value; var pvalue = pass.value; var xmlhttp; if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari