当前位置:K88软件开发文章中心编程语言JavaScriptCoffeeScript → 文章内容

CoffeeScript AJAX

减小字体 增大字体 作者:佚名  来源:网上搜集  发布时间:2019-1-15 15:33:49

由 珍珍阿姨 创建,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