breaststroke Posted February 1, 2012 Share Posted February 1, 2012 Hello! I am wondering whether we can make to calls to different pages within the same function.Something like this: function lcalls(){var xmlhttp;if(window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); }else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); }xmlhttp.open("GET","calls1.php",true);xmlhttp.send();xmlhttp.open("GET","calls2.php",true);xmlhttp.send();//maybe it would be enough to type just one send() at the bottom?} Or, if we could have two different functions within the same event.Something like this: <body onkeyDown="calls1(),calls2()"> I can try them, but I don't know whether to do that is correct or not.Thank you in advance. Link to comment Share on other sites More sharing options...
birbal Posted February 1, 2012 Share Posted February 1, 2012 you can use annonymouse function in onkeydown event to wrap two or moren function. <body onkeyDown="function(){calls1();calls2();}"> You can request as many page as you want through ajax.Requests will be paralal Link to comment Share on other sites More sharing options...
breaststroke Posted February 1, 2012 Author Share Posted February 1, 2012 Thank you very much birbal.I don't know anything about annonymouse functions yet, I will check it out.I conclude I can request two pages within the same function as I showed above. I will try.Regards Link to comment Share on other sites More sharing options...
justsomeguy Posted February 1, 2012 Share Posted February 1, 2012 The function you posted isn't going to work like you think it is because both requests use the same XHR object, the second request will cancel the first. Each needs its own connection. Link to comment Share on other sites More sharing options...
ShadowMage Posted February 2, 2012 Share Posted February 2, 2012 you can use annonymouse function in onkeydown event to wrap two or moren function.<body onkeyDown="function(){calls1();calls2();}"> I just want to elaborate a little more on this. Using the anonymous function the way you have here is not going to work like you think. Everything between the quotes is already placed in an anonymous function when the handler is created. So what you've essentially created is this:document.body.onkeydown = function() { function() { calls1(); calls2(); }} Notice that the inside function is only defined, and never called. You would have to place parens () at the end of the anonymous function to call it:function() { calls1(); calls2() }()but then you have a redundant and unnecessary nested function. You can make more than one statement in the event attributes just by separating them with semicolons:onkeydown = "calls1(); calls2();" Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.