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

  • Home
  • SEARCH
  • 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 8035969
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:28:06+00:00 2026-06-05T02:28:06+00:00

I’m trying to convert our current javascript framework to jQuery cause we’ll need the

  • 0

I’m trying to convert our current javascript framework to jQuery cause we’ll need the additional functionality of jQuery for further projects. There is one particular function that is all over the place (and it was setup how it was setup……) that I’d like to just override with a jQuery equivalent. Here’s the original Javascript function that makes an ajax call to a php page.

function ajax(n,f,v){
    var ajaxRequest;
    if(window.XMLHttpRequest){// code for IE7+, Firefox, Chrome, Opera, Safari
        ajaxRequest=new XMLHttpRequest();
    }
    else{// code for IE6, IE5
        ajaxRequest=new ActiveXObject("Microsoft.XMLHTTP");
    }
    ajaxRequest.onreadystatechange=function(){
        if(ajaxRequest.readyState==4 && ajaxRequest.status==200){

            //This is where the result is stored
            result = ajaxRequest.responseText;
            //parseScript pulls out the content and the div and populates the div with the retrieved content.
            parsed_result = parseScript(result);
            document.getElementById(parsed_result.div).innerHTML = parsed_result.source;
        }
    }
    ajaxRequest.open("GET","view.php?n="+n+"&f="+f+"&v="+v+"&time="+(new Date).getTime(),true);
    ajaxRequest.send();
}

function parseScript(_source) {
    var source = _source;
    var scripts = new Array();

    while(source.indexOf("<script") > -1 || source.indexOf("</script") > -1) {
        var s = source.indexOf("<script");
        var s_e = source.indexOf(">", s);
        var e = source.indexOf("</script", s);
        var e_e = source.indexOf(">", e);

        scripts.push(source.substring(s_e+1, e));
        source = source.substring(0, s) + source.substring(e_e+1);
    }

    for(var i=0; i<scripts.length; i++) {
        try {
            eval(scripts[i]);
            var div = div;
        }
        catch(ex) {
        }
    }

    return {source: source, div: div};
}

This is at the top of page that was just retrieve (hence the parseScript function). This div variable tells where to put the retrieved content.

<script>
    var div = 'content_1';
</script>
<!-- some retrieved html -->

The jQuery function I’d like to just “set on top” of the javascript function would require that I don’t edit the retrieve ajax file at all. See below for my attempt at the jQuery call.

function jAjax(n,f,v) {
$.get('view.php', 'n='+n+'&f='+f+'&v='+v, function(result) {
        if(result) {
            if($('#'+result.div).length) {
                $('#'+result.div).html(result);
            } else {
                console.log("Couldn't find the div= "+result.div);
            }
        } else {
            console.log("Couldn't find the names for n="+n+' f='+f+' v='+v);
        }
    });
}

So the question I have is how to I use jQuery to capture a variable from an ajax call so that I can populate that capture div with the retrieved html?

One other thing, yes I can can think of a bunch of ways to do it besides doing this, but this way would be easiest with the current framework that was already set in place when I got here. So, please only suggest ways of retrieving the variable from the ajax script. Thanks muchly!

  • 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-05T02:28:07+00:00Added an answer on June 5, 2026 at 2:28 am

    There is no built in way to get the value of variables in a javascript file that you retrieved through jquery ajax methods. You could, however, just call the parseScript function inside the $.get callback:

    $.get('view.php', 'n='+n+'&f='+f+'&v='+v, function(result) {
            if(result) {
                parsed_result = parseScript(result);
    
                if($('#' + parsed_result.div).length) {
                    $('#' + parsed_result.div).html(parsed_result.source);
                } else {
                    console.log("Couldn't find the div= " + parsed_result.div);
                }
            } else {
                console.log("Couldn't find the names for n="+n+' f='+f+' v='+v);
            }
        });
    

    EDIT:

    You may have to make this call with the longer $.ajax(…) method, setting the content type to text, because you have a script tag in the page.

    EDIT (ALTERNATIVE):

    You could simply reference the variable ‘div’ in the $.get callback because at that point the script would have been executed:

    $.get('view.php', 'n='+n+'&f='+f+'&v='+v, function(result) {
            if(result) {               
    
                if($('#' + div).length) {
                    $('#' + div).html(result);
                } else {
                    console.log("Couldn't find the div= " + div);
                }
            } else {
                console.log("Couldn't find the names for n="+n+' f='+f+' v='+v);
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
In my XML file chapters tag has more chapter tag.i need to display chapters
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

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.