Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery没有正确地获取内容_Javascript_Jquery_Url - Fatal编程技术网

Javascript jQuery没有正确地获取内容

Javascript jQuery没有正确地获取内容,javascript,jquery,url,Javascript,Jquery,Url,我目前在正确使用jQuery时遇到了一些问题。我正试图通过jQuery.get加载一些csv文件(即google.com),并构建一些图表。不知何故,jQuery无法正确加载文件。以下是我的代码: <html> <head> <!--Load the AJAX API--> <script type="text/javascript" src="https://www.google.com/jsapi"></scr

我目前在正确使用jQuery时遇到了一些问题。我正试图通过jQuery.get加载一些csv文件(即google.com),并构建一些图表。不知何故,jQuery无法正确加载文件。以下是我的代码:

<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>

$(document).keypress(函数(e){if(e.keyCode==13){updateData();};});
图纸(“2013.04.02”)
功能图(日期){
ajaxSetup({async:false});
var sql=”http://www.andrewpatton.com/countrylist.csv";
console.log(sql);
var-ans=jQuery.get(sql);
完成(…绘制…);
ans.fail(console.log(“fail”);
}

日期格式:YYYY.MM.DD

我已经测试了url,当我在浏览器中输入url时,它确实会返回一个.csv文件,所以我猜jQuery中有些东西我没有得到


有人能告诉我可能发生了什么吗?

正如@adeneo在评论中提到的,您在这里遇到了跨域请求问题。这是一个不受欢迎(但完全合理的)安全“特性”。要获得想要的结果,需要使用服务器端语言(PHP/Ruby/Python等)来获取CSV文件,必要时对其进行解析,然后在jQuery脚本中使用该数据

传统的解决方法是使用JSONP处理您的请求,但是当您想要加载
.csv
文件时,这种方法将不起作用


更多信息

旁注:为什么将async设置为false?我很确定是您没有正确获取内容,而不是jQuery?或者可能只是javascript的跨域策略开始发挥作用。是的……jQuery很好。。只是我不知道发生了什么。。