最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Uncaught TypeError: Cannot read property 'get' of undefined - Stack Overflow

programmeradmin0浏览0评论

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

$.get(".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.

.png

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

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

Share Improve this question asked May 9, 2014 at 8:48 user3393001user3393001 211 gold badge1 silver badge5 bronze badges 10
  • Did you include jQuery script in your document? – Ilija Dimov Commented May 9, 2014 at 8:49
  • You get this error if you haven't included jQuery correctly. Please read a tutorial first: learn.jquery./about-jquery/how-jquery-works. – Felix Kling Commented May 9, 2014 at 8:49
  • have you included the jquery api??? – ashishmaurya Commented May 9, 2014 at 8:50
  • Yes, it is included. Hmm – user3393001 Commented May 9, 2014 at 8:50
  • 1 @crisbeto That's not going to help if $ is undefined. – JLRishe Commented May 9, 2014 at 8:56
 |  Show 5 more ments

3 Answers 3

Reset to default 0

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

<script id="jquery" type='text/javascript' async defer src='//ajax.googleapis./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

Hope this help.

I had a problem like this in asp 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.

solution:

1.By adding jquery UI in package manager console

PM> install-package Jquery.UI.bined

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

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

I think this will work:

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


});
发布评论

评论列表(0)

  1. 暂无评论