开发者

coffescript and jquery ajax call [closed]

开发者 https://www.devze.com 2023-04-12 14:26 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. 开发者_StackOverflow中文版 Closed 10 years ago.

I am trying to make ajax call with coffescript and jquery and update form input type with result, but my input gets updated with [object XMLDocument] instead returned text

Here is coffescript code I use.

$ ->
 $('#get-mac').live 'click', (e) =>
     e.preventDefault()
     podaci = {broj : $('#contract_no').val(), action : 'get-mac-ua'}
     $.ajax '/hhh'
         type: 'POST'
         data: podaci
         datatype: 'text'
         success: (data) ->
             if data == 'False'
                 $('#mac').removeAttr "readonly"
                 alert 'Ne postoji MAC adresa na UA, upiši ručno'
             else
                 $('#mac').val data
                 $('#mac').removeAttr "readonly"
                 $('#contract_no').attr "readonly", true

here is old js version, that works

$(document).ready(function(){
$("#get-mac").live('click', function(e){
    e.preventDefault();
    var podaci = {broj : $('#contract_no').val(), action : 'get-mac-ua'};
    $.ajax({
      type: "POST",
      url: '/hhh',
      data: podaci,
      dataType: 'html',
      success: function(data){
          if(data == "False")
              {
                  $('#mac').removeAttr("readonly");
                  alert('Ne postoji MAC adresa na UA, upiši ručno');
              }
          else
              {
                  $('#mac').val(data);
                  $('#mac').removeAttr("readonly");
                  $('#contract_no').attr("readonly", true)
              }
        }
    });
  });
});


The significant difference between your JS code and your CoffeeScript is simply that you changed dataType to datatype. Capitalization matters! :)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号