I have the following script:
$ ->
$('#new_event').submit ->
$.post(
$(this).attr('action')
$(this).serialize()
success: (data, textStatus, jqXHR) ->
processData(data, textStatus, jqXHR)
)
return false
processData = (data, textStatus, jqXHR) ->
alert(data)
and so far I can’t for the life of me debug this. It renders as:
(function() {
var processData;
$(function() {
return $('#new_event').submit(function() {
$.post($(this).attr('action'), $(this).serialize(), {
success: function(data, textStatus, jqXHR) {
return processData(data, textStatus, jqXHR);
}
});
return false;
});
});
processData = function(data, textStatus, jqXHR) {
return alert(data); //BREAKPOINT HERE
};
}).call(this);
which looks okay to me. If I put the breakpoint on alert it never stops there. My javascript knowledge is pretty limited so I’m obviously missing something here. Would love to know what’s happening.
Thanks,
Dany.
I think your CoffeeScript is okay but your
$.postarguments are wrong. From the fine manual:So you don’t use the
success: fn(...)arguments with$.post, you just give it a function:or even:
or:
if you don’t mind the extra indentation and don’t need
processDataelsewhere.