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 8848269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:23:11+00:00 2026-06-14T12:23:11+00:00

I have problem in ajax and it doesn’t print the message I want. Let’s

  • 0

I have problem in ajax and it doesn’t print the message I want. Let’s explain.
In php code i have an input tag:

<input type="submit" id="login_button_add" name="submit" value="Add" 
onclick="add_building(); showbuildings( );" />

Those two js functions are:

function add_building(){
    var str1=document.getElementById("building_name").value;
    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("txtHint10").innerHTML=xmlhttp.responseText;}
    }
    xmlhttp.open("GET","add_building.php?q="+str1,true);
    xmlhttp.send();
}

In add_building.php I add a row in database and print messages. The query works fine, but it doesn’t print the message in my page with id that I have in my html code. I think that the problem is that I call second js function. Because when I call add_building() alone it works perfect(prints messages).

The php code of add_building.php is:

$q=$_GET["q"];


if ($q!==''){
$link= mysqli_connect(...);

mysqli_set_charset($link, "utf8");
$sql="SELECT * FROM buildings WHERE name='$q'";
$result = mysqli_query($link,$sql);

if (!mysqli_num_rows($result)){
mysqli_set_charset($link, "utf8");
$sql="INSERT INTO buildings VALUES ('','$q','')";
$result =mysqli_query($link,$sql);
echo "The building added successfully.";
}
else {echo 'Building name exists. Try a different.';}

@ db_close($link);
}
else{echo 'Please insert a name.';}

The other js function is:

function showbuildings(str)
{
    if (str=="")
    {
        document.getElementById("show_buildings_js").innerHTML="";
        return;
    } 
    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("show_buildings_js").innerHTML=xmlhttp.responseText;
        }
    }
    xmlhttp.open("GET","showbds.php?q=",true);
    xmlhttp.send();
}

In this function I print the table in my page. That works fine.

The problem is that the messages from add_building.php don’t print in id='txtHint10' ,
despite all the others in add_building.php work. I think that the problem is that I call second js function and I have two xmlhttp.responseText. Because when I call js function add_building() alone it works perfect and prints the messages.

  • 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-06-14T12:23:12+00:00Added an answer on June 14, 2026 at 12:23 pm

    The problem is that you are overwriting you xmlhttp variable with the second javascript function. The result is that only the callback from the second function is executed.

    For both functions to work independently of each other, you would need to use different variable names or declare them locally in each of your functions with var xmlhttp; (the cleaner solution).

    Note that the scope of a variable in javascript is global unless you declare it using var in your function.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have problem.. for(a=1;a<10;a++){ $(.div).append(<div id=+a+></div>) $.ajax({ url: file.php, data: a=+a, type: POST, async:
I have a problem with the following code, which doesn't want to work in
I have a problem with my JQuery, Ajax, and PHP code. I have a
I have a problem with this jQuery code. It doesn't work as expected: $('#select_dropdown').change
I have a problem. I want to send 3-4 variables from a PHP File
I have a strange problem with Jquery Ajax with the following code. Situation 1:
i have a little problem with my Ajax calls. Maybe i do not have
I have this problem that my sites uses alot of ajax and when a
I have a problem with an animation in jQuery using ajax. On the click
I have a problem consistently displaying Facebook Comments on my AJAX driven website. Each

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.