How to pass a callback as a parameter into another function

后端 未结 6 1712
生来不讨喜
生来不讨喜 2020-11-28 03:32

I\'m new to ajax and callback functions, please forgive me if i get the concepts all wrong.

Problem: Could i send a callbackfunction

6条回答
  •  遥遥无期
    2020-11-28 04:13

    Example for CoffeeScript:

    test = (str, callback) ->
      data = "Input values"
      $.ajax
        type: "post"
        url: "http://www.mydomain.com/ajaxscript"
        data: data
        success: callback
    
    test (data, textStatus, xhr) ->
      alert data + "\t" + textStatus
    

提交回复
热议问题