Jump to content

two calls to different pages within the same function


breaststroke
 Share

Recommended Posts

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

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

Edited by birbal
Link to comment
Share on other sites

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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...