简体   繁体   English

Coffeescript使用jQuery Ajax调用外部文档准备功能生成JS

[英]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.

相关问题 如何使用setTimeout()调用jQuery(document).ready之外的函数? - How to call function outside of jQuery(document).ready with setTimeout()? 在jQuery中document.ready函数外部的事件上调用函数 - Call functions on events outside document.ready function in jquery 调用document.ready之外的ajax函数 - calling ajax function that is outside document.ready 尝试从 jquery $(document).ready 调用外部 js 中定义的 function - Try to call function defined in external js from jquery $(document).ready 如何在 document.ready 上调用多个 js 函数而不放置它们 jQuery(document).ready(function(){}); - How to call multiple js functions on document.ready without putting them jQuery(document).ready(function(){}); jQuery文档已准备就绪,并按键可以调用一个函数 - jQuery document ready and keypress to call one function $(document).ready函数之外的JS全局变量和函数 - JS global variable and function outside $(document).ready function 如何从外部调用$(document).ready中的函数 - How to call a function within $(document).ready from outside it 为什么我不能从$ {document).ready调用外部函数 - why I cannot call outside function from $(document).ready 在 jQuery 中创建全局变量 document.ready function - Create global variable in jQuery outside document.ready function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM