1

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

7
  • Show the code, where you call get_CommentCount Commented Jun 13, 2016 at 7:41
  • where you have added handleData function? Commented Jun 13, 2016 at 7:41
  • @SurenSrapyan please check I update the code Commented Jun 13, 2016 at 7:42
  • And where you have defined handleData. I wonder you have problems with scope. Put a breakpoint into your success function and check 'this' value Commented Jun 13, 2016 at 7:43
  • 1
    @AzadChouhan your code seems to work fine: jsfiddle.net/k87ncaje. Could you show an example of the issue? Commented Jun 13, 2016 at 7:51

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

OP is passing it as callback(parameter), its pretty valid code
He is passing the function as a callback.
Then, the error is getting only after function call
1

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.

1 Comment

The function is being passed as a parameter - it's completely valid.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.