Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.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/69.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 YQL JSON脚本不返回?_Javascript_Jquery_Ajax_Json_Yql - Fatal编程技术网

Javascript YQL JSON脚本不返回?

Javascript YQL JSON脚本不返回?,javascript,jquery,ajax,json,yql,Javascript,Jquery,Ajax,Json,Yql,我这里有一个脚本,几乎是直接复制的。为什么下面列出的代码不返回任何内容 ajax.html: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content

我这里有一个脚本,几乎是直接复制的。为什么下面列出的代码不返回任何内容

ajax.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
  "http://www.w3.org/TR/html4/strict.dtd">

<html dir="ltr" lang="en-US">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Cross-Domain Ajax Demo</title>
    </head>
    <body>
        <div id="container">
            <form>
                <p><label>Type a URL:</label><input type="text" name="sitename" id="sitename"/></p>
                <p><input type="submit" name="submit" id="submit" value="Make Cross Domain Ajax request"</p>
            </form>
        </div>

        <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js" charset="utf-8"></script>
        <script type="text/javascript" src="cross-domain-requests.js"></script>

        <script type="text/javascript">
            $('form').submit(function() {
                var path = "www.google.com";
                requestCrossDomain(path, function(results) {
                    $('#container').html(results);
                });
                return false;
            });
        </script>
    </body>
</html>

(我对脚本和Ajax比较陌生,所以如果我做了什么蠢事,我会提前道歉。)

尝试将var yql中的回调更改为callback=?将select语句设置为“fromXML”,如下所示:

var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + site + '"') + '&format=xml&callback=?';

我的天哪,它能用,非常感谢你。这帮我节省了几个小时的睡眠,整晚都在想为什么它不起作用:DCool,我很高兴它起作用了。请将答案标记为已接受以结束此问题。我必须再等一分钟才能完成。对不起,我想我太新了,无法进行堆栈溢出编辑:对不起,我的意思是,它不会让我标记,因为答案回调中的问号不会生成随机字符串吗?YQL将无法以这种方式缓存任何内容,您将很快耗尽您的请求速率。
var yql = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent('select * from xml where url="' + site + '"') + '&format=xml&callback=?';