该代码的用途是什么 [英] What is the Use Of This Code

查看:106
本文介绍了该代码的用途是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

function SelectTrip(Adt_Fare, Adt_Tax, chd_Fare, chd_Tax, Inf_Fare, Inf_tax, Adt_Bfare, Chd_Bfare, Inf_Bfare, Tot_Fare, Adult, Child, Infant, airl, trav) {

         var xmlHttpReq = createXMLHttpRequest();
         xmlHttpReq.open("GET", "http://www.looknbook.com/FareDetails.ashx?Adt_Fare=" + Adt_Fare + "&Adt_Tax=" + Adt_Tax + "&chd_Fare=" + chd_Fare + "&chd_Tax=" + chd_Tax + "&Inf_Fare=" + Inf_Fare + "&Inf_tax=" + Inf_tax + "&Adt_Bfare=" + Adt_Bfare + "&Chd_Bfare=" + Chd_Bfare + "&Inf_Bfare=" + Inf_Bfare + "&Tot_Fare=" + Tot_Fare + "&Adult=" + Adult + "&Child=" + Child + "&Infant=" + Infant + "&airl=" + airl + "&trav=" + trav + "", false);
         xmlHttpReq.send(null);
         var yourJSString = xmlHttpReq.responseText;
         ShowContent('divfareDetails', yourJSString);

     }


     function createXMLHttpRequest() {
         try { return new XMLHttpRequest(); } catch (e) { }
         try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { }
         try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { }
         alert("XMLHttpRequest not supported");
         return null;

     }




为什么我们使用上面的代码




Why we use above code

推荐答案

实际上,我们(或者至少是我)不使用该代码(看起来很恐怖).
但是,它会向looknbook网站发出AJAX请求(例如,参见此处 .org/XMLHttpRequest_Call"target =" _ blank"title =" New Window> ^ ]).
Actually we (or, at least I) don''t use that code (it looks horrible).
However it makes a AJAX request to the looknbook website (see, for instance, here[^]).


您提供给我们的代码在尝试 Ajax [ ^ ].我轻蔑地坚持认为,在这种情况下,它必须称为Jax,因为这里没有异步发生.通过注册事件处理程序来处理onreadystatechanged事件来解决此问题.请参考以下网站以获取更多信息: http://en.wikipedia.org/wiki/XMLHttpRequest#The_onreadystatechange_event_listener [ ^ ].当readystate变为4时,responseText属性将包含从服务器返回的内容.

实际上,尽管完全不需要这样,因为有 jQuery [ ^ ],这也增加了跨浏览器兼容性的好处.在此处阅读如何使用jQuery使用 Ajax [
The code you presented us with is a bad attempt at doing Ajax[^]. I contemptuously insist that it must rather be called Jax in this case, because there is nothing asynchronous going on here. Solve this by registering an event handler to handle the onreadystatechanged event instead. Please refer to the following site for more information: http://en.wikipedia.org/wiki/XMLHttpRequest#The_onreadystatechange_event_listener[^]. When the readystate becomes 4 the responseText property will contain the content that was returned from the server.

Actually though there is no need to it like that at all as there is jQuery[^] which also adds the benefit of cross browser compatibility. Read here how to do Ajax with jQuery[^].

Regards,

Manfred


这篇关于该代码的用途是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆