簡體   English   中英

未捕獲的TypeError:undefined不是函數jquery

[英]Uncaught TypeError: undefined is not a function jquery

我真的對ajax和jsonp陌生,並且在調用文件時讀取文件時遇到問題。 該代碼有效。 但是每次我在同一腳本中再次調用同一函數時,都會說“未捕獲的TypeError:未定義不是函數”。 如果該功能運行一次,就不總是可以運行嗎?

這是我的代碼示例

var resultAmount = 0;

start = function(teamFile, rowsInDB, ratio_Over_rows, opplastx_gp, callfunction){

    //ajax ONLY calls don't return anything
    (function($) {
    //Connects to the json teamFile
    var url = 'http://xxx.co.uk/football/'+teamFile+'.json?callback=?';
    //Automatic refresh

    $.ajax({
    type: 'GET',
    url: url,
    async: false,
    jsonpCallback: 'jsonCallback',
    contentType: "application/json",
    dataType: 'jsonp',
    success: function(data) {

        if(callfunction == 'mep'){

            resultCount(data, rWin, count);
            resultCount(data, rDraw, count);
            resultCount(data, rLose, count);

            //the total of w/d/l
            resultAmount =  total[rWin] + total[rDraw] + total[rLose] ;

        }else{}

    },
    error: function(e) {
       console.log(e.message);
    }
});
})(jQuery);

}


//Adds the results w, d, l up
 resultCount = function(for_data, result, count_r){

    count_r = 0;

    //Goes through the data
    for(k in for_data){
        //if equals w, d, 1
        if(for_data[k].Results == result){
            //Add 1
            count_r++;
        }else{

        } 
    }
  }

//Then I call the function start twice only one works
console.log(start('ast', 7,5,5, 'mep'));
console.log(start('ars', 7,5,5, 'mep'));

僅第一個函數運行,而第二個則不運行,提示“未捕獲的TypeError:未定義不是函數”。 當我在第一個函數運行時更改它們時,第二個函數說“未捕獲的TypeError:未定義不是函數”。

如果有幫助,我的文件如下所示

jsonCallback([{"Brad Guzan":"yes","Jed Steer":"no","Ashley Westwood":"yes","Fabian Delph":"no","Ron Vlaar":"yes","Andreas Weimann":"yes","Gabriel Agbonlahor":"no","Nathan Baker":"yes","Leandro Bacuna":"yes","Karim El Ahmadi":"no","Christian Benteke":"no","Ciaran Clark":"no","Matthew Lowton":"yes","Ryan Bertrand":"yes","Antonio Luna":"no","Marc Albrighton":"yes","Libor Koz\u00e1k":"no","Aleksandar Tonev":"no","Yacouba Sylla":"no","Grant Holt":"yes","Joseph Bennett":"yes","Chris Herd":"no","Jordan Bowery":"no","Jores Okore":"no","Gary Gardner":"no","Daniel Johnson":"no","Nicklas Helenius":"no","Jack Grealish":"no","Janoi Donacien":"no","Callum Robinson":"no","last_gp":"lose","2nd_gp":"lose","3rd_gp":"win","4th_gp":"lose","5th_gp":"lose","Home":"home","Results":"lose"});

我發現這兩個文件都具有“ jsonCallback”作為正在讀取的文檔上的函數。 每個jsonCallback或函數都應該是唯一的。 以前發生的是沖突,而現在卻是獨特的。

考試:

function handleData( responseData ) {
    // do what you want with the data
    console.log(responseData);
}

$.ajax({
    url: "hi.php",
    ...
    success: function ( data, status, XHR ) {
        handleData(data);
    }
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM