0

Here is the design: 1) on index.html - ajax call is made by client as the dataset selected 2) processor.php - creates the new csv file of the data generated by mysql query 3) index.html callback - causes d3.js to take the dataset from csv file and to produce a graph 4) Repeat step 1 to 3 - does not allow d3 to get the most recent csv file

I am able to retrieve CSV file through d3 the first time AJAX call is made, however, afterwards Ajax calls from client side does not allow d3 to retrieve the newest file., the code does not take the most recent file

So here is the index.html

$.post( 'processor.php',
        $("#queryform :input").serializeArray(),
        function(data) {

                    d3.csv('diagrams/chord.csv', function (error, data) {
                    var mpr = chordMpr(data);

                    mpr
                      .addValuesToMap('chimp')
                      .setFilter(function (row, a, b) {
                        return (row.chimp === a.name && row.performedon === b.name)
                      })
                      .setAccessor(function (recs, a, b) {
                        if (!recs[0]) return 0;
                        return +recs[0].count;
                      });
                    sliderbanimate()
                    drawChords(mpr.getMatrix(), mpr.getMap());

                  });

This is only partial code but what I am trying to achieve is during th Ajax call, I want d3 plugin to use most recent CSV file

here is the processor.php - creates a new CSV file created from MYSQL on AJAX call

            $chordquery = mysqli_query($connection, 'SELECT a.CName as CName, a.Performed_on as performed_on,Count(*) as Count
                                FROM behavior a WHERE 
                                BName IN ('.$behaviourarry.') GROUP BY CName, performed_on');       

                    $num = 0;

                    while($resultchord = mysqli_fetch_array($chordquery)) {

                        $rel[$num]['chimp'] = $resultchord['CName'];
                        $rel[$num]['performedon'] = $resultchord['performed_on'];
                        $rel[$num]['count'] = $resultchord['Count'];
                        $num++;
                        //$data2[] = $row3['CName'];
                        //echo $row3['CName']."-".$row3['performed_on']."-".$row3['BName']."-".$row3['Year']."-".$row3['Count']."<br/>";
                    }

                    $output = fopen("diagrams/chord.csv",'w') or die("Can't open php://output");
                    //header("Content-Type:application/csv"); 
                    //header("Content-Disposition:attachment;filename=pressurecsv.csv"); 
                    fputcsv($output, array('chimp','performedon','count'));
                    foreach($rel as $relation) {
                    fputcsv($output, $relation);
                    }
                    fclose($output) or die("Can't close php://output");

Really hope if someone can help me out here...cheers!

K Shah
  • 1
  • Generate and append a random number to the end of the url, [as explained here](http://stackoverflow.com/questions/9692665/cache-busting-via-params) – meetamit Nov 19 '14 at 06:58
  • hi meetamit...i tried your recommendation but it's still not updating the graph when ajax is re-called.any other suggestion? – K Shah Nov 20 '14 at 01:23
  • Can't tell. What does the developer panel show? Is the 2nd query returning up to date data? If so, are there js errors in the console? Use console.log() to examine places in the code where there may be bugs. Insert a debugger statement and check things from within your code. – meetamit Nov 20 '14 at 03:33

1 Answers1

0

When developing/debugging, if your data is stored in a file, you are going to load that file many times. Soon enough your browser will use the cached version and not reload it each time. That’s great for speed, but not so great if you edit your file as part as your debugging process: changes would be ignored! By adding a hash and a random string of character at the end of the file name, you are effectively telling your browser to get your file from a different url, although it is the same file. What this does is that it will force your browser to reload the file each time. Once you’re happy with the shape of your file, you can stop doing that (by omitting the refresh parameter) and the browser may use a cached version of your file.

--jeromecukier.net

Alex Epelde
  • 1,679
  • 1
  • 15
  • 16