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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T05:24:32+00:00 2026-06-04T05:24:32+00:00

The following is my code: $.post( index.php?component=static_content&action=rules_count, { region:rname,page_url:page_url}, function(data1) { alert(data1); var num

  • 0

The following is my code:

$.post(
    "index.php?component=static_content&action=rules_count", 
    { region:rname,page_url:page_url},
    function(data1) {
        alert(data1);
        var num = $(data1).find('.ruleNum').html();
    }
);
alert(num);

But on line alert(num); there is an error num is undefined. Any idea what I am doing wrong?

Help much appreciated.

  • 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-04T05:24:34+00:00Added an answer on June 4, 2026 at 5:24 am

    you declared the variable num inside your post callback, so outside that function the variable is clearly undefined

    But even if you define it outside, its value won’t be displayed as you expected, since ajax is asynchronous (so that, when you alert the variable the ajax call is still running)

    if you need to acces num even outside just call another function passing the variable, e.g.

    $.post(
        "index.php?component=static_content&action=rules_count", 
        { region:rname,page_url:page_url},
        function(data1) {
            alert(data1);
            continueProcess(data1);
        }
    });
    
    var continueProcess = function(num) {
       alert(num);
    }
    

    or use Deferred Objects (since ajax methods return a promise since jQuery 1.5) you can also do

    $.when($.post(...).done(function(num) {
       alert(num)
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Please consider the following code, <form action=index.php method=post name=adminForm enctype=multipart/form-data> <input type=hidden name=showtime[] id=showtime_1
I am using the following code to post my form data to player/index.php and
I am working with the following code: action.php <?php $_SESSION['passtext'] = $_POST['passtext']; ?> index.php
I've written the following code to get JSON data with a POST request. $.post(http://example.com/songs/search_api/index.php,
I have the following code $.post( /factory/set,{ key : value }, function(response) { });
this line is in onCreate function JSONObject cat = getJSONfromURL(http://localhost/2010/hkinterview/index.php?op=androidCat); The following code is
I have the following code in my index.php page: // Write the resulting JSON
I have the following code . var last_id = ''; $('.products').each(function(){ $.ajax({ type: POST,
I have the following code: function get_login() { hideshow('loading2',1); error(0); $.ajax({ type: POST, url:
I put a Ajax link using the following code: echo chtml::ajaxLink('GO', 'http://localhost/index.php?r=user/delete', array('method'=>'POST')); But,

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.