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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:49:49+00:00 2026-06-06T06:49:49+00:00

I am trying to use AJAX for a web app game that im making.

  • 0

I am trying to use AJAX for a web app game that im making.

In short, I have the following HTML:

<li id='fight'><div id='change'></div></li>

In the following JS, you’ll see that when the user clicks “fight” a script runs to replace the content in ‘main’

I also want the user to be able to alternatively click “change” which should be inside “fight” and have it change main as well.

Currently, when the user clicks “change” it runs the script, changes main, then runs “fight” and changes it again.

I need to to only run “change” when the user clicks on that.

JS:

$("#fight").click(function() {
    var page = 'fight';
    getmain(page)
});

$("#change").click(function() {
    var page = 'change';
    getmain(page);
    evt.stopPropagation();
});

function getmain(page){
     $.ajax({
            type: "POST",
            async: false,
            url: 'welcome/loadmain',
            dataType: 'json', 
            data: { page: page },
            success: function(content){
                var html = '';
                html += content['content'];
                $('#main').html(html);
            }
        });    
}

$.ajax({
    type: "POST",
    async: false,
    url: 'welcome/loadmain',
    dataType: 'json', 
    data: { page: 'get_zone' },
    success: function(content){
        var html = '';
        html += content['content'];
        $('#fight').html(html);
    }
});   

HTML

    public function get_zone()
    {
        $user_id = $this->tank_auth->get_user_id();
        $itemroll = $this->db->query("SELECT current_zone, z.name FROM user_load ul
                                    INNER JOIN zones z
                                    ON z.id = ul.current_zone
                                    WHERE ul.user_id = $user_id");
        $result = $itemroll->row_array();
        $zone['current_zone']= $result['current_zone'];
        $zone['name'] = $result['name'];
        //HTML Formatting
        $content = '';
        $content .= "<div id='zonename'>Zone = ". $zone['name']. "</div>";
        $content .= "<div id='change'>Change Zone</div>";
        return $content;
    }
  • 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-06T06:49:51+00:00Added an answer on June 6, 2026 at 6:49 am

    Change

    $("#fight").click(function() {
        var page = 'fight';
        getmain(page)
    });
    

    to

    $("#fight").click(function(e) {
        if ($(this).is(e.target)) {
            var page = 'fight';
            getmain(page);
        }
    });
    

    This makes the event only get processed if the event target is the element the event is bound to.

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

Sidebar

Related Questions

I am trying to write an ajax web app. I have a function that
I'm trying to write a web app that needs to expose some methods that
I am trying to learn how to write more dynamic web sites that use
I am creating an iOS web app that has a fixed div (say 200px
Trying to do a simple web app with jquery mobile. I have put together
I'm trying to use Google's AJAX (JSON) Web Search API in Python. I'm stuck
I'm trying to implement a web chat for my website. I will use AJAX
I'm trying to make an Ajax Web Application that uses bread-crumbing to allow the
I have been trying to use an ajax-style file upload component (like the dojox
I'm trying to use Ajax accordion and the telerik RadScriptmanager to have an AJAX

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.