- ·上一篇文章:CoffeeScript jQuery
- ·下一篇文章:CoffeeScript 回调绑定
当前位置:K88软件开发 → 文章中心 → 编程语言 → JavaScript → CoffeeScript → 文章内容
CoffeeScript AJAX
由 珍珍阿姨 创建,Carrie 最后一次修改 2016-08-13 AJAX问题你想要使用jQuery来调用AJAX。解决方案$ ?= require 'jquery' # 由于 Node.js 的兼容性$(document).ready -> # 基本示例 $.get '/', (data) -> $('body').append "Successfully got the page." $.post '/', userName: 'John Doe' favoriteFlavor: 'Mint' (data) -> $('body').append "Successfully posted to the page." # 高级设置 $.ajax '/', type: 'GET' dataType: 'html' error: (jqXHR, textStatus, errorThrown) -> $('body').append "AJAX Error: #{textStatus}" success: (data, textStatus, jqXHR) -> $('body').append "Successful AJAX call: #{data}"jQuery 1.5和更新版本都增加了一种新补充的API ,用于处理不同的回调。request = $.get '/' request.success (data) -> $('body').append "Successfully got the page again." request.error (jqXHR, textStatus, errorThrown) -> $('body').append "AJAX Error: ${textStatus}."讨论其中的jQuery和$变量可以互换使用。另请参阅Callback bindings。
CoffeeScript AJAX