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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:55:31+00:00 2026-05-25T00:55:31+00:00

I have a javascript variable that is created in php echo var.$locallist.=.create_js_variable($locallist,$db2_list_all,’db2′); and it

  • 0

I have a javascript variable that is created in php

echo "var".$locallist."=".create_js_variable($locallist,$db2_list_all,'db2');

and it looks in html page source code like

var locallist={
  'CARINYA':[['2011-08-24-09-22 - w','20110824092216w'],['2011-08-18-13-15','20110818131546']],
  'COVERNAN':[['2011-03-02-12-28','20110302122831']],
  'DAVID':[['2010-12-22-19-43','20101222194348'],['2010-12-08-14-10','20101208141035']]};

Now I want to update the variable on button click via ajax

    jQuery.ajax({
        type: 'get',
        dataType: 'text',
        url: url,
        data: {
            what: 'db2list', 
            t: Math.random() 
        },
        success: function(data, textStatus){
            locallist = data;                   
            console.log(locallist);
        }
    });

and the ajax calls this php code (note that it’s the same php function that is called)

if($what == 'db2list') {
    $db2_list_all = get_db2_database_list();
    echo create_js_variable($locallist,$db2_list_all,'db2');
}

Console.log reports that

  • before update the variable is an object
  • after update it is a text

How can I fix that? So my other javascript code works again?

  • 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-25T00:55:31+00:00Added an answer on May 25, 2026 at 12:55 am

    Well, look at your ajax call:

    jQuery.ajax({
        type: 'get',
        dataType: 'text',
        url: url,
        data: {
            what: 'db2list', 
            t: Math.random() 
        },
        success: function(data, textStatus){
            locallist = data;                   
            console.log(locallist);
        }
    });
    

    Notice you’ve got the dataType as text? It’s going to bring the data in and treat it as text. Try changing the dataType to ‘json’. That will convert the data that was brought in to a regular ‘ol object, just like what you already have.

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

Sidebar

Related Questions

I have javascript string variable with var sttr=We prefer questions that can be answered
I have a variable that I'm using to build a JavaScript function call, and
I have a paragraph of text in a javascript variable called 'input_content' and that
In Javascript, I have a variable that is set to a block of text
I know that javascript doesn't have pointers in terms of a variable referring to
I've been writing some jQuery functions that have JavaScript variables and looping, etc inside
I have a javascript function (function1) that checks some global variables (can the user
I have a long snippet of HTML I want some javascript variable to equal
I have a select control, and in a javascript variable I have a text
Can you setup a variable for javascript in one page and have another page

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.