0

I'm currently having some trouble using the jQuery properly. I'm trying to load some csv files (ie google.com) via jQuery.get, and build some graph. Somehow the jQuery just cannot load the file properly.Here is my code:

<html>
    <head>

    <!--Load the AJAX API-->

    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
    <script type="text/javascript">


        $(document).keypress(function(e) {if(e.keyCode == 13) {updateData();};});

        drawchart("2013.04.02")

        function drawchart(date){

            jQuery.ajaxSetup({async:false});

            var sql = "http://www.andrewpatton.com/countrylist.csv";

            console.log(sql);

            var ans= jQuery.get(sql);

            ans.done(...draw...);

            ans.fail(console.log("fail"));
        }

    </script>
    </head>

<body>

<input id="date-input" style=margin-left:160px type="text"  id="date" name="date" />
<input type="button" value="submit" onClick="updateData();"/>
<p style=margin-left:160px> Date format: YYYY.MM.DD </p>

</body>
</html>

I have tested the url, and it indeed returns me a .csv file when I enter the url in the browser, so my guess is that there's something with the jQuery that I don't get...

Can someone tell me what might be going on?

user1948847
  • 955
  • 1
  • 12
  • 27

1 Answers1

0

You are running into cross domain request issues here, as @adeneo mentioned in the comments. This is an unpopular (but totally justified) security "feature". To get the results you want, you will need to use a server-side language (PHP/Ruby/Python etc) to get the CSV file, parse it if necessary, and then use that data in your jQuery script.

The traditional work around for this thing is to use JSONP for your request, but as you want to load a .csv file, that approach will not work.

More info here

Community
  • 1
  • 1
Nick Tomlin
  • 28,402
  • 11
  • 61
  • 90