夜鸣猪 发表于 2013-1-29 08:41:12

标准coffeescript 调用ajax

$.ajax '/',    type: 'GET'    dataType: 'html'    error: (jqXHR, textStatus, errorThrown) ->      $('body').append "AJAX Error: #{textStatus}"    success: (data, textStatus, jqXHR) ->      $('body').append "Successful AJAX call: #{data}"

单个select的调用
$(document).ready(function() {    $('#display_arms').change(function(){      $.ajax({url: 'YOUR URL',      data: 'display_arms=' + value,      success: function(data){          $('#display_arms').html(data);          }      })    });});
一组select的onchange
$("form.submit_on_change").each(function(idx,form){$(form).find("select,input").each(function(idx,element){    $(element).change(function(){      $(form).submit();      return false;    });});});

function PopulateDropdown() {    $.ajax({      type: "POST",      url: "../CommonWebService.asmx/GetData",      data: "{}",      contentType: "application/json; charset=utf-8",      dataType: "json",      success: function (msg) {            $("select").empty();            $.each(msg.d, function () {                $("select").append($("<option></option>").val(this['IdIndexDataType']).html(this['DataTypeName']));            });             $("select").css("width", "auto");          },      error: function (e1) {            alert("Error - " + e1.toString());      }    });}

function badFixSelectBoxDataWidthIE() {    if ($.browser.msie) {      $('select').each(function() {            if($(this).attr('multiple') == false) {                $(this).mousedown(function() {                  if($(this).css("width") != "auto") {                        var width = $(this).width();                        $(this).data("origWidth", $(this).css("width")).css("width", "auto");                        // If the width is now less than before then undo                        if($(this).width() < width) {                            $(this).unbind('mousedown');                            $(this).css("width", $(this).data("origWidth"));                        }                  }                })                // Handle blur if the user does not change the value                .blur(function() {                  $(this).css("width", $(this).data("origWidth"));                })                // Handle change of the user does change the value                .change(function() {                  $(this).css("width", $(this).data("origWidth"));                });            }      });    }}

if (jQuery.browser.msie) {jQuery('#mySelect').focus(function() {    jQuery(this).width('auto');}).bind('blur change', function() {    jQuery(this).width('100%');});};
页: [1]
查看完整版本: 标准coffeescript 调用ajax