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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T22:12:21+00:00 2026-05-29T22:12:21+00:00

I am busy developing a chrome extension. What it will do: Get data from

  • 0

I am busy developing a chrome extension.

What it will do:

  1. Get data from a PHP page (XMLHttpRequest)

  2. Split the result variable using .split

  3. And when someone clicks on a div, it will call a function to insert a css file with that name I got in number 1.

My problem:

Well nothing happens when I click that button. It works when I used the variable, “newvar”, instead of the variable, “currenttheme” from the XMLHttpRequest. I tried converting it to a string as well using .toString. Oh, alerting the variable does work and gives exactly the same response as newvar.

My code: (Sigh!)

//My XMLHttpRequest
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    user_data = xmlhttp.responseText;
    window.user_data = user_data;
    processdata();
    }
  }
xmlhttp.open("GET","http://localhost:8888/myphppage.php",true);
xmlhttp.send();

function processdata() {
//split result variable from PHP
var downdata = user_data.split('|||||');
var installedthemes = downdata[0];
currenttheme = downdata[1].toString();
window.currenttheme = currenttheme.toString();
}

function click(e) {
  newvar = "001";
  //insert css - works with variable newvar but not with this one
  chrome.tabs.insertCSS(null,
  {file:currenttheme + ".css"});
  //alerting the variable works, exactly the same as newvar
  alert (currenttheme);
}

document.addEventListener('DOMContentLoaded', function () {
   var divs = document.querySelectorAll('div');
  for (var i = 0; i < divs.length; i++) {
    divs[i].addEventListener('click', click);
  }
});
  • 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-29T22:12:23+00:00Added an answer on May 29, 2026 at 10:12 pm

    window.user_data = user_data;// <- not required. user_data = xmlhttp.responseText implies user_data is global to this window.
    window.currenttheme = currenttheme.toString(); <<- not required too

    also downdata[1] IS a string so replace

    currenttheme = downdata[1].toString();
    

    with

    currenttheme = downdata[1];
    

    If this doesn’t help, try alert(currenttheme); and see if you are getting the required theme name, because sometimes PHP can throw errors and die which may not produce a “|||||”. Check the php output and alert the xmlhttp.responseText too to see if everything is OK.

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

Sidebar

Related Questions

I'm busy implementing the wurfl api using PHP, but somehow just can't seem to
I´m busy converting an existing project from an Ant build to one using Maven.
I'm busy building an MVC application in PHP using Kohana MVC framework, and it
I am busy building an application in which I am reading data from more
Hi, I'm busy developing a Java EE app using Hibernate and Spring. I have
I am developing one application which will send the request to server and get
I'm busy using Google Charts in one of my projects to display data in
We are busy developing a Java web service for a client. There are two
I am busy developing a Delphi App that uses F12 When I am running
I am busy developing 2 web based systems with MySql databases and the amount

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.