[英]Coffeescript generating js with jquery ajax call outside document ready function
Can anyone tell me why this coffee script: 谁能告诉我为什么这样的咖啡脚本:
$ ->
$('#btnLogin').live 'click', ->
$.ajax
url: 'user/login'
type: 'POST'
data: 'Username=' + $('#username').val() + '&password=' + $('#password').val()
success: (data, status, request) ->
alert data
Generates this javascript with the ajax call outside the document ready method? 使用document ready方法外的ajax调用生成此javascript吗?
(function() {
$(function() {
return $('#btnLogin').live('click', function() {});
});
$.ajax({
url: 'user/login',
type: 'POST',
data: 'Username=' + $('#username').val() + '&password=' + $('#password').val(),
success: function(data, status, request) {
return alert(data);
}
});
}).call(this);
I you aren't familiar with the site: http://js2coffee.org/ It's a great resource for testing out these issues. 我对站点不熟悉: http : //js2coffee.org/这是测试这些问题的好资源。 You can convert code between coffeescript from javascript very easily.
您可以非常轻松地在来自JavaScript的coffeescript之间转换代码。 I use it often when I run into these issues.
当我遇到这些问题时,我经常使用它。
This was actually a problem with tab spacing in visual studio, I changed the tab spacing while I was working on the file and it ballsed everything up. 这实际上是Visual Studio中制表符间距的问题,我在处理文件时更改了制表符间距,使所有内容聚集在一起。 I just deleted all the spacing and tabbed in on every line and then it generated the js I wanted
我只是删除了所有间距并在每一行上都加上了标签,然后生成了我想要的js
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.