javascript - "$"在 Visual Studio 中使用 jQuery 时未定义

标签 javascript jquery json visual-studio

我正在尝试学习如何使用 jQuery(使用 Visual Studio)获取 JSON 数据,但在 VS 中遇到运行时错误。

错误信息:JavaScript 运行时错误:“$”未定义

似乎 VS 只是不识别 jQuery。或者,我尝试通过他们的 CDN 引用外部 jQuery 库,但没有解决问题。

有人知道我为什么会遇到这个错误吗?

HTML:

<!DOCTYPE html>
<html>
<head>

    <title>JSON Test</title>

    <link href="/css/default.css" rel="stylesheet" />
    <script src="/js/jquery-1.10.2.min"></script>
    <script src="/js/default.js"></script>

</head>

<body>
    <button onclick="canWeGetData()">Get Data!</button>
</body>

</html>

默认.JS:

function canWeGetData() {

var error = "Null data!";
var success = "Good data!";

$.getJSON("http://ip.jsontest.com/?callback=showMyIP", function (data) {

    if (data == null) {
        document.writeln(error);
    }
    else {
        document.writeln(success);
    }

});

};

最佳答案

Jquery 不存在。

看这一行:

<script src="/js/jquery-1.10.2.min.js"></script> <!-- you missed the .js -->

另外,检查路径是否正确。或者简单地使用

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">

关于javascript - "$"在 Visual Studio 中使用 jQuery 时未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20368984/

相关文章:

javascript - 我如何使用 jquery mobile 在两个单独的 html 文件之间传递对象

json:不支持的类型:func()

javascript - 如何通过 AJAX 调用插入 IE 8 中的 "enable"HTML5 元素?

javascript - Angular2 添加 HTML 到动态元素

javascript - 取消回调函数的返回值

javascript - 将 JSON 数据本地加载到 JavaScript 文件中

JSON_MODIFY 按索引在 json 数组中插入值

CSS3 过渡 - Javascript 库

javascript - 第二张图像的 onclick 应该变为事件状态(即进行 next() 调用)

jquery - 1.7.2 中的顺序 jQuery 动画