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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:25:05+00:00 2026-06-06T16:25:05+00:00

This is a page using a single jQuery.ajax posting to the same page and

  • 0

This is a page using a single jQuery.ajax posting to the same page and is working fine.

<?php 
if (!isset($_POST['varA'])) {
?>
<html>
    <head>
        <script type="text/javascript">
            $(document).ready(bingo);

            function bingo()
            {
                jQuery.ajax({
                    type: "POST",
                    data:  {varA: "123"},
                    success: function(data)
                    {
                        $("#test").html(data);
                    }
                });
            }
        </script>
    </head>
    <body>
        <span id="test"></span>
    </body>
</html>
<?php
}
else 
{
    print_r($_POST['varA']);
}
?>

Situation: I have another variable that I wish to set using another separate jQuery.ajax. However, my page content duplicated itself when I put them altogether like this.

Bad Example (depicting what I’m trying to do)

<?php 
    if (!isset($_POST['varA'])) {
    ?>
    <html>
        <head>
            <script type="text/javascript">
                $(document).ready(bingo);

                function bingo()
                {
                    jQuery.ajax({
                        type: "POST",
                        data:  {varA: "123"},
                        success: function(data)
                        {
                            $("#test").html(data);
                        }
                    });
                }

                function buttony() //added 2nd independent jQuery.ajax function
                {
                    jQuery.ajax({
                        type: "POST",
                        data: {varB: "456"},
                        success: function(data)
                        {
                            $("#test2").html(data);
                        }
                    });
                }
            </script>
        </head>
        <body>
            <span id="test"></span>
            <span id="test2"</span> //added 2nd span
            <input type="button" value="Clicky" onclick="buttony()"/> //added
        </body>
    </html>
    <?php
    }
    else 
    {
        print_r($_POST['varA']);
    }

    if(isset($_POST['varB'])) //added isset() checking
    {
        print_r($_POST['varB']);
        echo 'varB Okay';
    }
    else
    {
        echo 'varB Not';
    }
?>

Additional information: Posting of variables for both jQuery.ajax of “Bad Example” are working fine.


Note: Pictures below are not from the codes above, just an example of what I meant by “content duplicated itself”.

Before

Before

After

After


Question: May I know where should I put my 2nd jQuery.ajax function and isset() checking of the POST variable, in such a way that both jQuery.ajax functions will work correctly and won’t conflict with each other?

  • 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-06T16:25:07+00:00Added an answer on June 6, 2026 at 4:25 pm

    I used window.location to replace the use of 2nd jQuery.ajax to avoid complication.

    Sample example

    Inside JavaScript function

    window.location = "samePage.php?varB=abc";
    

    Checking of POST variable varB

    if(isset($_REQUEST['varB'])
    {
        $getValue = $_REQUEST['varB'];
    }
    

    I’m leaving the question open for the community to tackle on how to do proper nesting of using 2 or more jQuery.ajax in the same page.

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

Sidebar

Related Questions

i have this simple code to load data from other php page using get
I'm using nested pages in Jquery Mobile: Looks like this: // wrap page <div
Im parsing the source of a website and Im using this regex: /page\.php\?id\=([0-9]*)\\>(.*)\<\/a\>\<\/span\>/.match(self.agent.page.content) self.agent.page.content
I use the following datepicker.php page for jquery datepicker is given below: <!DOCTYPE html>
I am building a calendar web page using jQuery and asp.net-mvc similar to this
I'm using jquery uniform on one of the project I'm working on. Since this
I'm using jquery mobile and backbone.js to create a single page mobile application. The
I'm using the code from this page http://jsfiddle.net/gnQUe/170/ jquery slide toggle as a form
I'm trying to create a page by using view 2. This page list all
This is my Iservice1.cs page using System; using System.Collections.Generic; using System.Configuration; using System.Data; using

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.