Passing a callback function to jQuery AJAX success function

后端 未结 1 1553
囚心锁ツ
囚心锁ツ 2021-02-19 21:12

I\'m trying to pass in a function to run when the AJAX call is successful, however it\'s not working as it say\'s that \"callback is not a function\".

Example:

C

1条回答
  •  故里飘歌
    2021-02-19 21:47

    showGradesBox is a string in your code. So you have two options to execute the callback function:

    If you want to keep the string you can use

    this[callback](response);
    

    (if callback is defined in global scope you can also use window[callback](response);

    Or you can pass the function directly:

    var callback = showGradesBox;
    

    (in this case you can keep your existing code for callback execution)

    0 讨论(0)
提交回复
热议问题