Tag: 回调

没有调用Ajax回调。 如何解决这个问题?

我再次提出你的建议。 我有一些AJAX调用来从我的编辑器运行代码,这是一个PHP在线编辑器。 (你们可以在我的网站上查看。) 我有一些ajax调用发送编辑器的数据和接收输出。 问题:for循环未正确执行。 以下for循环程序成功执行 1;$i–){ echo “$i”; } ?> 虽然这个for循环没有执行 <?php for ($x=0; $x<=10; $x++) { echo "The number is: $x “; } ?> 当我通过FireBug运行时,我得到一个响应,说for循环在第二个循环(上图)的情况下变成了一个无限循环。 现在这是我的AJAX回调: $.ajax({ type: ‘GET’, url: ‘exec.php’, data: code, success: function(data) { alert(data); $(loader).addClass(“hidden”); var stdout = $(form).children(‘.stdout’); if (data.search(“Parse error”)>0) { var str = data.replace(“Parse error: “,””); $(stdout).html(str); […]

jQuery .fadeIn()和.fadeOut()在将代码重写为递归回调后,回调工作不按预期工作

重写的代码应显示任意数量的图片,旧代码是静态的。 但是新代码的作用是立即显示arrays的最后一个图像以及所有图像的完全延迟,因此30秒。 我的旧代码看起来像这样,并且与jquery回调一起运行良好。 http://pastebin.com/XH2aRqBh 重写的代码: //Class Trial Trial = (function() { function Trial(imageArray) { this.images = imageArray; } Trial.prototype.startTrial = function() { $(“#noise”).hide(0, this.showImages(this.images)); }; Trial.prototype.showImages = function(imageArray) { imageToShow = imageArray.pop(); if(imageToShow === undefined){ $(“#noise”).show(0); console.log(“show noise”); return; } console.log(“pop image : “, imageToShow.image.src, ” delay : “, imageToShow.delay); $(“#img”).show(); $(“#img”).attr(“src”, imageToShow.image.src); $(“#img”).fadeIn(0).delay(imageToShow.delay).fadeOut(0, this.showImages(imageArray)); […]

jQuery文件上传插件 – 在IE <10中未触发的失败回调

我使用的是https://github.com/blueimp/jQuery-File-Upload 它在现代浏览器中使用XHR文件上传,在oldIEs中使用隐藏的iframe上传(8,9)。 文件validation失败时,服务器返回4xx状态代码(错误/失败)。 $(‘#fileupload’).fileupload({ url: url, dataType: ‘json’, done: function (e, data) { console.log(“done”) }, fail: function (e, data) { console.log(“fail”) } }) 但是在oldIE中,即使我发送4xx状态代码,也会调用完成回调。 有没有办法让它调用失败回调( https://github.com/blueimp/jQuery-File-Upload/wiki/Options#fail )并读取响应正文或状态代码? 我认为它可能需要使用隐藏的iframe上传文件的方法,但我找不到文档中的任何特定内容。

JQuery – 连续多次调用函数时,为什么只有最后一次调用的回调才能正确执行?

有一个函数在完成时触发回调; 我连续称这个function2或3次; 只有最后一次调用的回调才能达到预期的效果; 以下描述和代码举例说明了真实情况。 我有三对div。 我需要切换每对中的一个div并在其对不再可见时更改剩余可见div的状态。 然后,我创建了一个隐藏div并改变另一个div的背景颜色的函数。 我这样做是因为每当用户点击按钮显示描述和其他非必要项目时,我都想调用此function。 不幸的是,结果不是我预期的结果。 如果用户多次调用该函数,而不让该函数完成它的任务,则只有最后一个绑定的回调才能正常运行,其他的不会改变div的背景颜色或者会不同步由于延迟而与另一个div。 这是javascript: function toggleLayer(layerId,layerId2) { //element1 is the first div of the pair. The one to be hidden. element1 = $(“#”+layerId); //element2 is the second div of the pair. The background-color of this one will be changed when the element1 is hidden. element2 = $(“#”+layerId2); //Hiding […]

jQuery插件:调用回调方法,然后可以根据响应调用插件函数

我正在编写jQuery插件并将它们与AJAX集成。 我正在削减脂肪并专注于基础知识: (function($) { function MyPlugin(el, options) { this.element = $(el); this.myInput = false; this.options = $.extend( { onSave:function(){} }, options); this.initialize(); } $.fn.myPlugin = function(options) { var control = new MyPlugin(this.get(0), options); return control; }; MyPlugin.prototype = { initialize:function() { var me = this; //specifics shouldn’t really matter //it creates some HTML to go […]

不能直接将 .play()作为jQuery回调

考虑以下代码: var music = $(“audio”)[0]; //doesn’t work $(“#pbutton”).click(music.play); //works $(“#pbutton”).click(function(){music.play()}); 无效的行在Firefox中返回此错误: TypeError: ‘play’ called on an object that does not implement interface HTMLMediaElement. 我在这里错过了什么吗? 为什么这不起作用? 更新:我为此做了一个小提琴 。

jquery函数将html代码加载到div中,然后将其他内容加载到html加载的div中

我想知道将html页面(page1.html)加载到活动网页(index.html)中的div中的方法是什么,然后将另一个html页面(page2.html)加载到将在页面内的div中已加载(page1.html)。 我的意思是。 的index.html load 脚本 $(document).ready(function() { $(‘a.link’).live(‘click’, function() { $(‘#content’).load(‘page1.html’, function(){ $(‘#content2’).load(‘page2.html’); }); }); }); page1.html 只需单击一下就可以正常工作,第二次单击它会加载page2.html 0.5秒,然后加载page1.html。 有什么问题 ??? 谢谢

submit()函数有回调吗?

我有这个代码,以及一个提交到框架的文件上传表单: setMyCookie(‘name’,’value_1′); $(‘.myform’).submit(); setMyCookie(‘name’,’value_2′); 问题:Webkit浏览器似乎在表单被提交之前用’value_2’更新’MyCookie’,或者在它被提交的确切时刻更新,因此错误的cookie值随之发送。 我希望在提交表单后立即将cookie值更改为“value_2”,以便cookie可以用于其他请求。 以下代码工作正常,但我不认为使用timeout()是最好的解决方案。 也许有另一种方法来解决这个问题? setMyCookie(‘name’,’value_1′); $(‘.myform’).submit(); setTimeout(function(){setMyCookie(‘name’,value_2);},100); 谢谢。

在jquery click事件中将参数传递给回调函数

直接的业务: 我有一个jquery事件监听器,如下所示: $(“.number”).click(printNumber); 和回调函数: function printNumber(number){ console.log(number); } 我想知道我是否可以将一个参数传递给回调,所以它看起来像这样 $(“.number”).click(printNumber(number)); (我知道它会立即调用该函数,但是,有没有办法将参数传递给它) 先感谢您!

jQuery回调没有等待fadeOut

在我看来,以下代码应该产生这些结果: mademoiselle demoiselle mesdemoiselles 相反,随着“ma”淡出,“mes”在制作序列时消失: mademoiselle madesdemoiselles mesdemoiselles 代码: mamesdemoiselles $(document).ready(function() { $(“.remove”).fadeOut(4000,function(){ $(“.add”).fadeIn(5000); }); }); 编辑:我发现一个空的跨度,如果我删除使该bug消失: mamesdemoiselles 问题是:生成这个的PHP代码使用跨度作为占位符。 如果必须的话,我会对它们进行调整,但我很好奇为什么会发生这种情况。