简体   繁体   中英

Getting error in jquery ajax “function not defined”

I am returning some values from jquery ajax. I am getting the result but with this I am also getting a error. Please first of all take a look at code

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

calling this function like this

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

Its give me error that TypeError: handleData is not a function . Please anybody tell me why I am getting this error. I have gone through the stackoverflow questions but I am not finding any solution for me. May be you find it duplicate but I post this question after surfing the stackoverflow.

Thanks

I think the problem here is that you are passing an anonymous function to get_CommentCount. Try with a normal function, it should work better.

In the success function of your ajax you have wrote handle(data), and it is a function that you havent wrote any where may be, so this error is showing you that TypeError: handleData is not a function so you have define a function like

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

and this will works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM