Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7015105
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:36:33+00:00 2026-05-27T22:36:33+00:00

I have two JS functions that preforms AJAX calls, I’ve wanted to test them

  • 0

I have two JS functions that preforms AJAX calls, I’ve wanted to test them so I’ve created two paragraphs with different ids that will hold the result of the responses text:

<script type="text/javascript">      

    trackApplicationAdded('1139631160', '12445'); //should change test1 paragraph
    trackApplicationRemoved('1139631160'); //should change test2 paragraph

</script> 

<p>Test1: <span id="test1"></span></p>
<p>Test2: <span id="test2"></span></p> 

When I run each function on its own (commenting on of them), each one changes its own paragraph as expected, but when I run both of them, I can only see the paragraph change made by the LAST function.

I have a function that creates an XMLHttpRequest that gets the variable test which send the paragraph id that should be changed by each function (and as noted, it is working when each one is called by itself).

function sendRequest(url, params, test)
{

 // code for IE7+, Firefox, Chrome, Opera, Safari
if (window.XMLHttpRequest)
{
    httpRequest=new XMLHttpRequest();
}     
else // code for IE6, IE5
{
    httpRequest=new ActiveXObject("Microsoft.XMLHTTP");
}

httpRequest.open("POST", url, true); 

//Set request headers for POST command//
httpRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpRequest.setRequestHeader("Content-length", params.length);
httpRequest.setRequestHeader("Connection", "close");

 httpRequest.onreadystatechange=function()
 {
    if(httpRequest.readyState==4 && httpRequest.status==200)
    {
        //Here you can see "test" which, depends on the function, is test1 or test2//
        document.getElementById(test).innerHTML=httpRequest.responseText;
    }
 }

httpRequest.send(params);

//end when the server will responde we will execute the "document.getElementById("txtHint").innerHTML=xmlhttp.responseText;" //

}

By the way, the AJAX preforms database insert by PHP functions and its everything working good in any situation. It is important to note that the problem is only with the paragraph changes and not what happens in the server.

Any one have an idea how to solve this ? Thanks…

EDIT

Here is the code of the 2 functions:

function trackApplicationAdded(fID, fappID) 
{    

var url = "trackApplicationAdded.php";
var params = "facebookID=" + fID + "&facebookApplicationID=" +fappID;

sendRequest(url,params, "test1");  
}


function trackApplicationRemoved(fID) 
{    

var url = "trackApplicationRemoved.php";
var params = "facebookID=" + fID;

sendRequest(url,params, "test2");  
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:36:33+00:00Added an answer on May 27, 2026 at 10:36 pm

    You forgot var when you declared “httpRequest”, so the second call overwrites the first. Without the var declaration the variable is global.

    At the top of “sendRequest()” just add:

    var httpRequest;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two functions that have different enough logic but pretty much the same
I have two functions that I want to run on different threads (because they're
Say I have two functions that expect ...rest parameters private function a(...myParams):void { trace(myParams.length);
So I have two jquery functions that bassically do the same, but on 2
I have two functions to add and remove table rows that contain a form
I have an IF statement that consists of two separate function calls passing values
I have two functions that pulling some of content from html and returning it
I have two functions that access the internet on the APP start. I've tried
I have two functions that i'm hoping i can put into one and can
I have two functions that generate DOM elements. They both attempt to create the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.