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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T22:40:42+00:00 2026-05-26T22:40:42+00:00

I am using jQuery in my web site. Following is the code i am

  • 0

I am using jQuery in my web site. Following is the code i am getting problem with:

 $("#activitiesbtn").click(function(){
    $('#dashboard-mainsubhead').load('activity.html', function() {
        // doing some stuff here

        // Following code is making problem
        $('.subareas').bind('click', function(){
            var keytext = $(this).find('.areakey').text();

            $.ajax({
                type: 'POST',
                url: 'http://localhost:8888/getactivity',
                data: {activitykey: keytext},
                success: function(result) { 
                    activityobj = jQuery.parseJSON(result);
                }
            });

            var activityurl = activityobj.mapurl;
            var activmapurl = "<img src=\""+activityurl+"\"></img>";
            $('#activity-mapimg').html(activmapurl);
            $('#activity-activitykey').html(activityobj.key);
            $('#activity-activitymode').html(activityobj.activityMode);
            $('#activity-time').html(activityobj.totalTimeTaken);
            $('#activity-distance').html(activityobj.totalDistanceCovered);
            $('#activity-calories').html(activityobj.calories);
            $('#activity-wallutas').html(activityobj.wallutas);

            alert("subarea div clicked");
        });
    });
});

problem is that first time when i click any of div which has subareas class, nothing happens. But after that every time when i click any subareas class div, alert “subarea div clicked” comes but text of other divs changes on every second click. Why is it happening? Any idea? Thanks in advance.

  • 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-26T22:40:42+00:00Added an answer on May 26, 2026 at 10:40 pm

    First, you need to unbind the click every time otherwise the code will execute multiple times.

    Second, you need to use the data returned by the .ajax call only in the success event:

    $('.subareas').unbind("click");
    $('.subareas').bind('click', function(){
        var keytext = $(this).find('.areakey').text();
        $.ajax({
            type: 'POST',
            url: 'http://localhost:8888/getactivity',
            data: {activitykey: keytext},
            success: function(result) { 
                activityobj = jQuery.parseJSON(result);
                var activityurl = activityobj.mapurl;
                var activmapurl = "<img src=\""+activityurl+"\"></img>";
                $('#activity-mapimg').html(activmapurl);
                $('#activity-activitykey').html(activityobj.key);
                $('#activity-activitymode').html(activityobj.activityMode);
                $('#activity-time').html(activityobj.totalTimeTaken);
                $('#activity-distance').html(activityobj.totalDistanceCovered);
                $('#activity-calories').html(activityobj.calories);
                $('#activity-wallutas').html(activityobj.wallutas);
            }
        });
    });
    

    The variable activityobj won’t have any value outside the $.ajax() function the first time it executes – the second time it has the value of the previous call.

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

Sidebar

Related Questions

I am developing web site using jQuery and other tech. I have problem in
I have the following jQuery Code: $(#menu span).click(function() { var url = this.getAttribute(data-url); var
I am using ASP.NET MVC for developing a web site. I am using jquery
I've rewritten my family web site using JavaScript (JQuery) making Ajax calls to PHP
I'm using the following jQuery code to shuffle the video links on the left
I got a web site using jQuery, jQuery Tools and some handcrafted JS running
I have a problem here. I'm trying to manipulate a web page using jquery.
I am using JQuery mobile in asp.net web form website. I have the following
I am pretty new to jQuery in general, however the following code works perfectly
I'm using the following code to display two div containers after 3 minutes: /*

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.