coffescript and jquery ajax call [closed]
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! :)
精彩评论