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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:05:55+00:00 2026-05-19T11:05:55+00:00

I’m having issues passing parameters/variables into the ajax() function. The function below accepts two

  • 0

I’m having issues passing parameters/variables into the ajax() function.

The function below accepts two parameters. One is ‘element’, the success option of .ajax() uses, that works fine so no need to focus on that. The ‘tx’ is either a single value like ‘menu’ or a couple of values separated by a colon like this: “menu:categories:brands”

If there is only one value in ‘tx’ then only one AJAX request needs to be sent and that works fine. If there is more than one value in ‘tx’ the function split’s it using “:” is the delimiter and then passes offset[0] as the value of ‘tx’ into the AJAX request and then store’s the rest of the values in ‘x’.

What I’m having issues with is running this function recursively once the AJAX request is complete for the first value. The var ‘more’ stores a bool value if there is more values left to process or not. However, when I write in an if argument using ‘more == true’ into the success or complete option of .ajax() it doesn’t reflect the value stored in that variables, it always returns false.

Before some one answers, with “You should structure the function that calls this function to only pass a single value into that parameter,” lets suppose that this is an impossible venture that is outside the realm of my control.

I have no idea why this happening. I know it’s probably something very simple that I’m overlooking but I’ve been up for about 16 hours now and this issue has plagued me for at least half that time.

Any help here is appreciated. Here is the function:

function getContent(element, tx) {
    e = element
    modAmount = tx.split(':')
    if (modAmount.length > 1) {
        x = ''
        tx = modAmount[0]
        for (i=1;i<modAmount.length;i++) {
            x = x + modAmount[i]
            if (i != (modAmount.length)-1){
                x = x+":"
            }
        }
        more = true
    }
    else {
        more = false
        tx = modAmount[0]
    }
    $.ajax({  
        type: "POST",  
        url: "getModule.php",  
        data: "modName="+tx+"&DB=<?php echo DB ?>",  
        success: function(data){  
            if ($( element ).find('p').text() == "No Content"){
                $( element ).find('p').remove();
                $( element ).html("<div onclick='destroy(this)' id='destroy' class='ui-corner-all destroy' title='Remove Module'>"+data+"</div>")
            }
            else {
                $( element ).append("<div onclick='destroy(this)' id='destroy' class='ui-corner-all destroy' title='Remove Module'>"+data+"</div>");
            }
        },
        complete: function() {
            if (more == true) {alert(x)} // always returns false
        }
    });

}
  • 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-19T11:05:55+00:00Added an answer on May 19, 2026 at 11:05 am

    There’s already one glaring error here: you’re not declaring your local variables using the var keyword. This means that there’s only one instance of any of those variables, in the global context.

    I’m not sure if this is your problem, but it certainly seems like it could be. Consider the case where you call getContent “foo:bar”. The first call sets more to true, but then the second recursive call sets more back to false. When the first XmlHttpRequest finishes, the completion callback will see the value of false rather than the true you were expecting, since those two calls are sharing the same variable for more.

    You should read up on how JavaScript/ECMAScript scoping works, and gain a solid understanding of how closures work in the language. This will prevent a lot of head-scratching in the future. Google around for writings by Douglas Crockford; that’s a good starting point.

    tl;dr: define your local variables using the var keyword.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I'm making a simple page using Google Maps API 3. My first. One marker
Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out

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.