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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:26:26+00:00 2026-05-16T11:26:26+00:00

I have two files, one containing an array in PHP that is echo ed

  • 0

I have two files, one containing an array in PHP that is echoed via json_encode, and the other full of javascript functions for a webpage. One such function, that looks like this (and is unfinished):

/*
 * Function: selectVictim
 * Called from function laserOn()
 *
 * Selects a random victim from a list of victims
 *
 * @return String: victim
 */
function selectVictim()
{
var params = "url=queenofsheep.com/Sheep/victims.php";
var request = new ajaxRequest();

request.open("POST", "victims.php", true);
request.setRequestHeader("Content-Type",
                             "application/x-www-form-urlencoded");
request.setRequestHeader("Content-Length", params.length);
request.setRequestHeader("Connection", "close");

request.onreadystatechange = function ()
{
    if (this.readyState == 4)
    {
        if (this.status == 200)
        {
            if (this.responseText != null )
            {
                var vicString = this.responseText;
                var vicArray = eval('"'+vicString+'"');
                //var vicArray = vicString.split(',');
                //var numVic = Math.floor(Math.random() * (vicArray - 1));
                alert(vicArray);
            }
            else alert("Ajax error: No data received");
        }
        else alert("Ajax Error: " + this.statusText);
    }
}

request.send(params);
}

Is supposed to take in the array from the other file and do things to it that are beyond the scope of this question. Unfortunately, while this.responseText contains a JSON encoded array of the format

var jsonArr = 
     ["1","2,","3"]

activating the function does nothing, and evaling this.responseText yields “undefined.”

What am I doing wrong here? I can provide more examples of the real code, the actual array, whatever, if need be. This is driving me crazy.

  • 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-16T11:26:27+00:00Added an answer on May 16, 2026 at 11:26 am

    Try adding “(” and “)” to the Eval Function. That’s how I’ve seen it done in the past

    var myObject = eval('(' + vicString + ')');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two types of JavaScript files. One contains static code and the other
I have two files. file1 has the data like belowing containing only one column.
I have two tables in Sql Server, one containing IDs for files and the
I have two .csv files containing correlation matrices exported from R. One file contains
I have two files one with senators who are retiring and one of complete
I have two template files: one for the form (loginFormTemplate) and one for the
Here I am trying to implement the jQuery I have two main files one
Say I have two files where there is one number per line File 1
Is it possible to have two app.config files where one app.config serves as a
I have the two following text files: First one: chr10 1000 1001 DEL 2.4807

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.