【问题标题】:Checking for failure in ajax request in coffeescript在 coffeescript 中检查 ajax 请求是否失败
【发布时间】:2016-04-13 23:20:55
【问题描述】:

我想在coffeescript 语法中使用.post jquery 方法来发出post 请求。 coffeescript 文档提供了添加成功回调的示例,但没有提供添加错误回调的语法。我该怎么做?

$.post '/',
    userName: 'John Doe'
    favoriteFlavor: 'Mint'
    (data) -> $('body').append "Successfully posted to the page."
    # Callback for error case?

【问题讨论】:

    标签: javascript jquery ajax coffeescript


    【解决方案1】:

    You should check jQuery.post() APIjQuery.ajax() API 可以让您在方法选项中定义这两个回调。

    $.post('/',
      userName: 'John Doe'
      favoriteFlavor: 'Mint'
      (data) -> $('body').append "Successfully posted to the page."
    ).fail((data) -> "Error handler")
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-05-27
      • 2012-01-20
      • 2021-01-28
      • 1970-01-01
      • 2011-07-03
      相关资源
      最近更新 更多