Tag: 异步

jQuery ajax async’true’让我的web-app卡住,直到返回数据

我正在研究基于PHP的Web应用程序(我没有构建)。 我正在运行这个ajax请求: $.ajax({ type: ‘POST’, url: “/potato/ajax.php?module=test_module”, dataType: ‘json’, async: true, data: { start_ts: that.start_date, stop_ts: that.end_date, submitted: true }, beforeSend: function() { console.log(‘Start: ‘ + new Date().toLocaleString()); // Show Chart Loading that.qwChart.showLoading({ color: ‘#00b0f0’, // text: that.returnNumWithPrecent(that.progress) text: that.qwChartProgress }); // If data div isn’t displayed if (!that.dataDisplayed) { // Show divs loading that.showMainDiv(); […]

每个()循环中的jQuery AJAX解决方案

我注意到当我在.each()循环中使用jQuery中的AJAX时遇到问题。 脚本执行时,仅更新数据库中的第一条记录。 这是我的脚本: function save(){ var _userTypeId; var _userTypeName; var _isDeleted; var request; $(“tr.recUserType”).each(function(){ $this = $(this); _userTypeId = $this.find(“#userTypeId”).html(); _userTypeName = $this.find(“#userTypeName”).val(); _isDeleted = $this.find(“#isDeleted”).val(); request = $.ajax({ url: “save.php”, type: “POST”, data: {userTypeId: _userTypeId, userTypeName: _userTypeName, isDeleted: _isDeleted} }); }); request.done(function(){ document.location.reload(); }); request.fail(function(){ alert(“Request Failed!”); }); } 以及save.php的内容: <?php include_once "globals.php"; dbConnect(); […]

jQuery延迟不按顺序调用resolve / done回调

代码示例: http : //jsfiddle.net/MhEPw/1/ 我有两个jQuery Deferred对象。 我希望发生多个“异步”请求 – 并且在它们全部运行之后我希望回调(.done函数)按照指定的顺序运行。不幸的是它们不按顺序运行。 也许我正在寻找Deferred不提供的一些function?

AJAX没有更新变量

jQuery的 我正在发出一个AJAX请求,用来更新服务器的响应来更新变量( foo )的值。 这是我正在使用的代码: //## My variable ## var foo = “”; //## Send request ## $.ajax({ url: “/”, dataType: “text”, success: function(response) { foo = “New value:” + response; }, error: function() { alert(‘There was a problem with the request.’); } }); //## Alert updated variable ## alert(foo); 问题是foo的值仍然是一个空字符串。 我知道这不是服务器端脚本的问题,因为我要么得到错误警报,要么至少得到字符串”New value:” 。 这是一个演示问题的JSFiddle: […]

异步和同步术语

当与编程相关时,我对术语异步感到困惑。 在编程术语中,它似乎与字典中定义的相反。 例如, 同步一词意味着: 发生在同一时间; 时间一致; 同期; 同时。 继续以相同的速度和完全一起; 一起重复。 然而,维基百科说: “在编程中, 异步事件是独立于主程序流的事件。异步动作是在非阻塞方案中执行的动作,允许主程序流继续处理。” 是不是“非阻塞”并且允许“主程序流程继续处理”的同步或“同时发生”? 似乎同步一词表示“非阻塞”和异步,“阻塞”。 为什么这些术语在与编程相关时似乎反向使用,或者它与我不理解的低级计算有关? 当我使用同步AJAX调用时,我会执行以下操作… $.ajax({ url: somefile.php, async: false, success: { …code that gets run on success… } }); …code that gets run after the ajax-success code runs… 有了这个,它实际上在运行脚本的其余部分之前等待响应,这是一个阻塞动作。 那么为什么这个被称为同步,当它与任何其他过程不同步时,实际上却相反?

Ajax jquery异步返回值

如何在不冻结浏览器的情况下使此代码返回值。 你当然可以用新方法重写它。 function get_char_val(merk) { var returnValue = null; $.ajax({ type: “POST”, async: false, url: “char_info2.php”, data: { name: merk }, dataType: “html”, success: function(data) { returnValue = data; } }); return returnValue; } var px= get_char_val(‘x’); var py= get_char_val(‘y’); 编辑: 我需要在其他时间从php文件中获取至少20个变量。

$ .Deferred:如何检测每个承诺何时执行

我有许多需要完成的异步任务,所以我使用的是promises。 我需要检测每个承诺何时被执行(解决和拒绝)。 在此之前我不能继续执行。 我使用的是这样的东西: $.when(promise1, promise2, …).always(); 但是这段代码是错误的,因为when方法具有惰性求值,并且只要其中一个promise失败就会返回。 因此,只要其中一个承诺失败, always回调也会运行。 我正在考虑编写一个变通方法,但是这个用例很常见,可能有人已经完成了,或者甚至有一种方法可以使用jQuery(如果没有,添加Promise.whenNonLazy或者很好) Promise.when(promise1, promise2, …, false) 。 这可能吗?

JQuery同步动画

在许多情况下,我希望动画同步执行。 特别是当我想制作一系列连续动画时。 有没有一种简单的方法可以使jQuery animate函数调用同步? 我想到的唯一方法是在动画结束时将标志设置为true并等待此标志。

将递归函数转换为异步CPS实现(javascript)

这是我的function。 function duplicate_step_through_highlighted (element_jq, target_jq, char_cb) { console.log( element_jq); var contents = element_jq.contents(); for (var i = 0 ; i < contents.length; ++i) { // if text node, step if (contents[i].nodeType === 3) { // insert empty text node var new_tn = document.createTextNode(''); target_jq.append(new_tn); // iterate it var text = contents[i].nodeValue; for (var j = […]