Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/445.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 .js文件未在firefox中运行-随附代码_Javascript_Ajax_Json - Fatal编程技术网

Javascript .js文件未在firefox中运行-随附代码

Javascript .js文件未在firefox中运行-随附代码,javascript,ajax,json,Javascript,Ajax,Json,这些文件有什么问题吗?我试图在我的Firefox浏览器上查看输出,但我无法这样做。什么也没出现。这只是一个空白屏幕 我使用的是Ubuntu 13.04。任何帮助都将不胜感激 这些是我的档案 index.html <!DOCTYPE html> <html> <head> <script src="script.js" type="text/javascript"></script> </head> <

这些文件有什么问题吗?我试图在我的Firefox浏览器上查看输出,但我无法这样做。什么也没出现。这只是一个空白屏幕

我使用的是Ubuntu 13.04。任何帮助都将不胜感激

这些是我的档案

index.html

<!DOCTYPE html>
 <html>
 <head>
     <script src="script.js" type="text/javascript"></script>
 </head>
 <body>
     <pre id='json' style='white-space: pre-wrap'></pre>
 </body>
</html>

script.js

$(document).ready(function(){

var req = {
    format: 'json',
    action: 'parse',
    page: 'New York City',
    prop: 'text',
    section: 0
};

$.ajax({
    url: '//simple.wikipedia.org/w/api.php',
    data: req,
    cache: true,
    dataType: 'jsonp',
    success: function(result) {
        // Add result's HTML to the top of the <body>
        $('body').prepend(result.parse.text['*']);
        // Append full JSON result to output
        $('#json').text(JSON.stringify(result, '', 2));
    }
});
});
$(文档).ready(函数(){
var req={
格式:“json”,
操作:“解析”,
第页:“纽约市”,
道具:“文本”,
章节:0
};
$.ajax({
url:“//simple.wikipedia.org/w/api.php”,
数据:req,
是的,
数据类型:“jsonp”,
成功:功能(结果){
//将结果的HTML添加到
$('body').prepend(result.parse.text['*');
//将完整的JSON结果追加到输出
$('#json').text(json.stringify(result',2));
}
});
});

该url看起来有误。您可能应该有一个协议:
“http://simple.wikipedia.org/w/api.php“
您使用的是jQuery,但未定义库。将它添加到主脚本之前。您使用的jQuery(?)库具体在哪里?我使用的是在线编辑器。代码在那里运行得很好。脚本似乎没有添加到html页面中。请尝试使用控制台(firefox/chrome)进行调试,这样可以解决许多问题。