本文介绍了Parallele Ajax,响应处理程序的参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 亲爱的朋友们, 我是ajax的新手。简单的请求没有问题 - 但似乎当我设置响应处理函数时,我只能传递函数名和 不给参数,所以我遇到问题开始,例如5 ajax 请求平行。怎么做到这一点?对于一个案例,我使用了* b $ b *不同* resp。处理程序,我通过全局 变量来解决问题 - 但现在我有一个例如20次拨打*相同* r.handler并且我不知道如何告诉功能*使用哪个* b 请求使用。我希望解决方案很简单,但是如何...没有什么 在快速谷歌上发现,对不起... 提前提前!有一个愉快的周日和周,daniel 解决方案 新的什么?我假设你正在使用一些Ajax库。 您可以使用匿名函数和闭包来实现,或者您可以使用 函数构造函数。 如果没有看到原始代码,我就不能告诉你如何修改它。 On Sun,2007年8月12日05:05:36 -0700,David Mark < dm *********** @ gmail.comwrote: 嗨大卫,谢谢你的快速回复。 新的什么?我假设你正在使用一些Ajax库。 Ajax新手。不,如果没有必要,我不喜欢图书馆。实际上我建立了自己的b $ b,但这是另一个话题。我一直希望/使用/ 了解原始字样。代码和对象......在开头。 你可以使用匿名函数和闭包来实现,或者你可以使用函数构造函数。 好吧它就像[requestId的东西是我的如上所述调用 不同响应处理程序的解决方法] 函数wuwinoAjax(script,responseHandler,paraString,reqId){ requestId =(reqId)? reqId:''firstRequest''; httpRequest [requestId] = false; if(window.XMLHttpRequest){// Mozilla, Safari,... httpRequest [requestId] =新的XMLHttpRequest(); if(httpRequest [requestId] .overrideMimeType) httpRequest [requestId] .overrideMimeType(''text / xml''); }否则if(window.ActiveXObject){// IE 尝试{ httpRequest [requestId] = new ActiveXObject(" Msxml2.XMLHTTP"); } catch(e ){b / b 尝试{ httpRequest [requestId] = new ActiveXObject(" Microsoft.XMLHTTP"); } catch(e){} } } if(!httpRequest [requestId] ){return false; } httpRequest [requestId] .onreadystatechange = responseHandler; httpRequest [requestId] .open(''GET'',rootURL + ''wuwino / ajax.php?script =''+ script + paraString,true); httpRequest [requestId] .send(null); } httpRequest = new Array(); requestToUse = new Array(); //默认 requestToUse [''updateTraittypeBoxes''] =''firstRequest''; << ....用例如... requestToUse [''updateTraittypeBoxes''] =''secondRequest''; ajax(''traittypes'' ,updateTraittypeBoxes,''traittypeId = 55'', ''secondRequest''); << ....而responseHandler确实...... 函数updateTraittypeBoxes(){ http_request = httpRequest [requestToUse [''updateTraittypeBoxes'']]; .... } << 提前再次使用Thanx! Ajax新手。不,如果没有必要,我不喜欢图书馆。实际上我建立了自己的b $ b,但这是另一个话题。我一直希望/使用/ 了解原始字样。代码和对象......一开始。 好。 [snip] IE7也在这里结束,所以评论不准确。 为什么要覆盖MIME类型?是否在 服务器上设置不正确? 你在这里滥用数组。在这种情况下,你应该对象 对象。 实际上这是一个就绪状态处理程序。 由于此函数被调用为请求对象的方法,因此你可以将b / b减少到: http_request = this; 看起来你不需要跟踪其他任何东西,所以 只是删除了两个数组。 hi dear folks, i''m new to ajax. simple request no problem - but it seems when I setthe response handler function, I can only pass the function name andnot give parameters, so I have a problem when starting e.g. 5 ajaxrequests parallele. how to do that correctly? for one case, where Iused *different* resp. handlers, I solved the problem by globalvariables - but now I have a loop of e.g. 20 calls to the *same*r.handler and I don*t know how to tell the function *which* request ofthe 20 to use. I expect the solution to be simple but how... nothingfound on a quick google, sorry... thanx in advance! have a nice sunday and week, daniel 解决方案 New to what? I assume you are using some Ajax library. You do it with anonymous functions and closures or you can use theFunction constructor. Without seeing your original code, I can''t tell you how to modify it. New to what? I assume you are using some Ajax library.New to Ajax. No I don''t like libraries if not necessary. Actually Ibuild my own, but that''s another topic. I always wish to have/ use/understand the "original" code and objects... in the beginning. You do it with anonymous functions and closures or you can use theFunction constructor.Without seeing your original code, I can''t tell you how to modify it. ok it''s just like [the requestId stuff is my workaround for callingdifferent response handlers in parallele as mentioned] function wuwinoAjax (script, responseHandler, paraString, reqId) { requestId = (reqId) ? reqId : ''firstRequest'' ; httpRequest[requestId] = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... httpRequest[requestId] = new XMLHttpRequest();if (httpRequest[requestId].overrideMimeType)httpRequest[requestId].overrideMimeType(''text/xml''); } else if (window.ActiveXObject) { // IE try {httpRequest[requestId] = newActiveXObject("Msxml2.XMLHTTP");} catch (e) { try {httpRequest[requestId] = newActiveXObject("Microsoft.XMLHTTP");} catch (e) {}}} if (!httpRequest[requestId]) { return false; } httpRequest[requestId].onreadystatechange = responseHandler;httpRequest[requestId].open(''GET'', rootURL +''wuwino/ajax.php?script='' + script + paraString, true);httpRequest[requestId].send(null);} httpRequest = new Array();requestToUse = new Array();//defaultrequestToUse[''updateTraittypeBoxes''] = ''firstRequest''; << .... called with eg... requestToUse[''updateTraittypeBoxes''] = ''secondRequest'';ajax(''traittypes'', updateTraittypeBoxes, ''traittypeId=55'',''secondRequest''); << .... and the responseHandler does... function updateTraittypeBoxes () { http_request =httpRequest[requestToUse[''updateTraittypeBoxes'']]; ....} << Thanx again in advance! New to Ajax. No I don''t like libraries if not necessary. Actually Ibuild my own, but that''s another topic. I always wish to have/ use/understand the "original" code and objects... in the beginning. Good. [snip] IE7 also ends up in here, so the comment isn''t accurate. Why are you overriding the MIME type? Is it not set properly on theserver? You are misusing arrays here. In this context, you should Objectobjects. Actually this is a ready state handler. Since this function is called as a method of the request object, youcan reduce this to: http_request = this; It doesn''t appear that you need to keep track of anything else, sojust delete the two arrays. 这篇关于Parallele Ajax,响应处理程序的参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-16 03:37