javascript 未捕获的类型错误:无法读取未定义的属性“get”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23560299/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 01:05:42  来源:igfitidea点击:

Uncaught TypeError: Cannot read property 'get' of undefined

javascriptgetresponse

提问by user3393001

Why am I getting this error, when I'm trying to get a response from a file on my own server?

当我尝试从我自己服务器上的文件中获取响应时,为什么会出现此错误?

$.get("http://www.example.com/user.php?q=" + client + "", function(response) { 

if(response == "invalid"){
console.log("invalid login");       

    return;
}

And btw, the string client is mentioned already in the code.

顺便说一句,代码中已经提到了字符串客户端。

And jquery is included.

并且包括 jquery。

http://i.gyazo.com/693e6633d211ab6da79598e75c6dde58.png

http://i.gyazo.com/693e6633d211ab6da79598e75c6dde58.png

回答by keypaul

I have solve the problem like this ( i have jquery loaded async so i check if is defined and then get a css...etc..)

我已经解决了这样的问题(我已经异步加载了 jquery,所以我检查是否已定义,然后获取 css ......等等)

<script id="jquery" type='text/javascript' async defer src='//ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js?ver=1.8.3'></script>
<script type='text/javascript'>
    (function checkJQuery(){
        if ('undefined' == typeof window.jQuery) {
            setTimeout(function(){checkJQuery();},250);
        }else{
            var css = "url-of-my-css";
            console.log("my css is loading");
            window.jQuery.get( css, function( data ) {
                $('<style>'+ data +'</style>').appendTo(document.getElementsByTagName('head')[0]);
                console.log("css loaded");
            });

            var js = document.createElement('script'); 
            js.type = 'text/javascript';
            js.async = 'async';
            js.defer = 'defer';
            js.src = 'url-of-my-js';
            var node = document.getElementsByTagName('script')[1];
            node.parentNode.insertBefore(js, node);
        }
    })();
</script>

Changing $.get to window.JQuery.get

将 $.get 更改为 window.JQuery.get

Hope this help.

希望这有帮助。

回答by zokaee hamid

I had a problem like this in asp.net mvc 5.

我在 asp.net mvc 5 中遇到了这样的问题。

<script>    
function OpenBulkUpload() {           
$.get("/AdminPanel/BulkUpload/Index").then(
function (r) {
$("<div id='DivBulkUpload'></div>").html(r).dialog(
{
width: 'auto', height: 'auto', modal: true, title: "Upload Pictures",
close: function () { $('#DivBulkUpload').remove(); }}); 
});
}
</script>

show Uncaught TypeError: Cannot read property 'get' of undefined in debuger browser.

显示未捕获的类型错误:无法在调试器浏览器中读取未定义的属性“get”。

solution:

解决方案:

1.By adding jquery UI in package manager console

1.通过在包管理器控制台中添加jquery UI

PM> install-package Jquery.UI.combined

2.And add scripts and links in top of cshtml page

2.并在cshtml页面顶部添加脚本和链接

<script src="~/Scripts/jquery-1.10.2.js"></script>
<script src="~/Scripts/jquery-ui-1.11.4.js"></script>
<link href="~/Content/themes/base/all.css" rel="stylesheet" />

My problem was solved.

我的问题解决了。

回答by RamGrg

I think this will work:

我认为这会奏效:

$.get("http://www.example.com/user.php?q=" + client, function(response) { 
    if(response == "invalid"){
       console.log("invalid login"); 
       return;
    }      


});