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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:34:56+00:00 2026-06-04T07:34:56+00:00

I am using ajax to connect to a PHP script and then retrieve the

  • 0

I am using ajax to connect to a PHP script and then retrieve the graph coordinates needed for the jqplot jQuery graphing library.

The problem is that I am having difficulties constructing a proper PHP array that can then be converted into a jQuery array that jqplot can read.

Here is the code that retrieves the array from the PHP file:

$.ajax({
    type: 'POST',
    dataType: "json",
    url: "behind_curtains.php",
    data: {
        monthSelected: month_option_selected
    },
    success: function (data) {
        var stored_data = data;
        alert(stored_data);
    }
});
return stored_data;
}

Here is the code that creates the jqplot

jQuery.jqplot('chartdiv-data', [], {
    title: 'Plot With Options',
    dataRenderer: stored_data,
    axesDefaults: {
        labelRenderer: jQuery.jqplot.CanvasAxisLabelRenderer
    },
    axes: {
        xaxis: {
            label: "Day",
        },
        yaxis: {
            label: "data"
        }
    }
});

If you could please help me create the proper data array in the behind_curtains.php file it would be great!

Edit 1
the graphing coordinates array should be in the form of:

[[[1,2],[3,5],[5,13]]]

and basically I need to somehow write php code that can output an array that stores data in that form.

Thanks

Solution:

*behind_curtains.php*

I put together an array that simply generates a string in the form of [[1,2],[3,5],[5,13]]. I then stored the string in a variable and echoed that variable in the form of:

echo json_encode($stored_data);

On the user side of things here is how my code looked like:

<script type="text/javascript">
$("document").ready(function() {
        $.ajax({
            type: 'POST',
            dataType:"json",
            url: "behind_curtains.php",
            data: {
                monthSelected: month_option_selected},
            success: function(data){                    
            var stored_data = eval(data) ;  
/* generate graph! */
$.jqplot('chartdiv-weight', [stored_data], {
 title: month, 
axesDefaults: {
    labelRenderer: jQuery.jqplot.CanvasAxisLabelRenderer
  },
  axes: {
    xaxis: {
      label: "Day",
    },
    yaxis: {
      label: "data"
    }
  }   
});
        }
        });
    }

}});</script>

I hope that helps, if no, whoever is interested please let me know.

  • 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-04T07:34:58+00:00Added an answer on June 4, 2026 at 7:34 am

    You can return the stored_data but you need to have it declared before the AJAX call, like shown in the bottom most example, here. You must also use: async: false otherwise you cannot return your data in this fashion. For the same reason if you like you could use getJSON() instead.

    As it goes to formatting your retrieved data a similar issue I answered here. You need to build your array accordingly to represent your data.

    If you can show how exactly does your JSON look like then I could give you a more precise answer.

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

Sidebar

Related Questions

I have a problem with charset on a php script using jQuery for AJAX
I have an AJAX request (using JQuery) that calls a PHP script which does
I am using PHP + jQuery AJAX to log a user into my site.
I am trying to fetch a PHP script using AJAX and return the values
Using Javascript (or Ajax) I want to connect to a page (a .php page)
I am currently using the JQuery ajax function to call an exterior PHP file,
I am using AJAX modal popup in my project, but there is problem with
I have started using ajax/jQuery in our websites / application. There are many plugins
I am using ajax and php and I grabbing all of the points out
I'm using ajax to get some data then based on the data use html()

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.