簡體   English   中英

在jquery中獲取錯誤ajax“函數未定義”

[英]Getting error in jquery ajax “function not defined”

我從jquery ajax返回一些值。 我得到了結果,但是我也得到了一個錯誤。 首先請看一下代碼

function get_CommentCount(handleData) {
    $.ajax({
        url: 'Profile/get_CommentCount',
        type: "post",
        dataType: 'json',
        success: function(data) {
            handleData(data);
        }
    });
}

像這樣調用這個函數

get_CommentCount(function(output) {
    console.log('output', output)
});

它給我一個錯誤, TypeError: handleData is not a function 請有人告訴我為什么我收到這個錯誤。 我已經完成了stackoverflow問題,但我找不到任何解決方案。 可能你發現它重復但我在瀏覽stackoverflow后發布了這個問題。

謝謝

我認為這里的問題是你將一個匿名函數傳遞給get_CommentCount。 嘗試使用正常功能,它應該更好。

在你的ajax的成功函數中你已經編寫了句柄(數據),它是一個你沒有寫過任何可能的函數,所以這個錯誤告訴你TypeError: handleData is not a function所以你已經定義了一個像

function handleData(data)
{
    alert(data);
}

這對你有用。

暫無
暫無

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

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