1

With this function:

function start() {
MONDUX();
Biggie();
}  

function MONDUX executes, and the AJAX call returns good data and is displayed correctly. However, Biggie() is a.w.a.l.

The result of this :

function start() {
Biggie();
MONDUX();
}  

is the opposite. Biggie() works as expected, MONUX() fails.

This doesn't do any good, down in the body:

<script type="text/JavaScript">
window.onload= start();
</script>  

and, this dodge is not helpful:

<body onload="start()">  

and that was tried like so also

Detest cargo~cult programming and running out of ideas here. Suggestions?

These resources were all related // near hits // no cigar. Loading javascript in body onload with 2 functions JS and Body(Window) Onload event JavaScript: How is "function onload() {}" different from "onload = function() {}"? That one was fascinating but way deep waters for me... How to onload two javascript files? meh... good, but...

?? :/~

<script type="text/javascript" >

 function MONDUX(){
if (window.XMLHttpRequest)
 { // code for IE7+, Firefox, Chrome, Opera, Safari
 xmlhttp=new XMLHttpRequest();
 }
else
  { // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
 {
 if (xmlhttp.readyState==4 && xmlhttp.status==200)
  {
  document.getElementById("WhatThexBobby").innerHTML=xmlhttp.responseText;
  }
 }
xmlhttp.open("POST","000 8 KISS 22solo PHP.php?figure1=5&figure2=33", true);
xmlhttp.send();

 alert(WhatThexBobby);

}
 </script>
 <script type="text/javascript" >

function Biggie(){

if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
 }
else
 {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
 {
 document.getElementById("FreakinEh").innerHTML=xmlhttp.responseText;
 }
 }
 xmlhttp.open("POST","000 8 KISS solo PHP.php?figure1=5&figure2=10", true);
xmlhttp.send();

alert(FreakinEh);
 }


 </script>
15
  • have you tried $(document).ready()? Commented Dec 17, 2012 at 5:23
  • 3
    What are Biggie and MONDUX? They must learn to cooperate. This will call both. Commented Dec 17, 2012 at 5:23
  • 1
    How sure are you that both functions aren't causing an error of some kind? In that case it doesn't matter which order the functions are called in, processing will cease before the other function is called. Commented Dec 17, 2012 at 5:25
  • AWAL = Absent Without Authorized Leave? Commented Dec 17, 2012 at 5:25
  • 1
    @MountainMan If the first one throws an exception, the other one will not run. Can you show us their code? Also please look if there's anything in the javascript console. Commented Dec 17, 2012 at 5:31

2 Answers 2

1

You're assigning the request to the global variable xmlhttp, and then reassigning that variable to another request before the first one has returned. I don't know if that is causing your problem, but it's definitely going to cause a problem. It's also very bad JavaScript practice.

Simple fix is to put the line 'var xmlhttp;' at the beginning of both functions.

Edit: Just in case you didn't know this: xmlhttprequest is asynchronous. You call 'send', and your remaining statements in the script and document continue to run while the request is being sent to the server. Only after the server returns do the various callback methods (onreadystatechange, and the like) get called, and this is long after your alerts were shown.

Sign up to request clarification or add additional context in comments.

4 Comments

@sakhunzai: Yes, I saw you ninja'd me on that after I posted. Sorry.
@user4815162342 magia! :) var xmlhttp; right after, below, the line : function X(){ ...just, wow. Now to use it, see if I can learn WHY it works. Thanks... I am trying to learn just enough to put a JavaScript UI for going to whatever image of 159, the user wishes to got to, on the website listed on my profile. Now, having a way to get multiple variables on the main php script will help.
I'll leave that figuring out WHY as an exercise for you :)
@user4815162342 getting warmer..link Good stuff. Section, "Scopes have memory"
0

Considering one of them is throwing some error, would it not be good idea to put them in Try Catch ? Something like,

function start() {
  try
  {
    MONDUX();
  }
  catch(err)
  {
   // handle error
  }
  try
  {
    Biggie();
  }
  catch(err)
  {
    //Handle error
  }
  finally
  {
   // cleanup
  }
}  

This will ensure both runs even if one of them mis-fires.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.