I am submitting a form with ajax.

In my controller I have something like:

```
if @message.valid?
 render json: { msg: @message.content }
else
 render json: { error: 'Reply could not be sent.' }
end

```

In my view I have the form

```
<%= form_for @message, remote: true do |f| %>

```

Then in my view I have the following javascript

```
$('.message').bind('ajax:success', function(xhr, data, status) {
 $(this).before('<p>'+data.msg+'</p>');
  });

$('.message').bind('ajax:error', function() {
 alert("Error: Message could not be sent.");
});

```

I can't get the ajax error to initiate. I assume its how I'm passing the json error message in the controller.