I'm sending information back-and-forth between a Rails controller and a JS file.
I'm sending the form to the controller through JS (works)
$("#help-email-submit").ajaxSubmit({url: '/help/send_help_email', type: 'post' });I'm able to catch the event in the controller (works)
def send_help_email .... endIn the same JS file that sent the above request, how do I capture the JSON response (below)? (doesn't work)
def send_help_email ... cst_str = @current_support_ticket.to_s respond_to do |format| format.json { render :json => cst_str } end endIn the JS file
var xmlhttp = new XMLHttpRequest(); alert(xmlhttp.responseText);
UPDATE
I noticed a JS error that is preventing the success: function from executing:
Error
TypeError: 'undefined' is not a function (evaluating '$("#help-email- form").ajaxSubmit({url: '/help/send_help_email', type: 'post', complete: handlerResponse })')
This is the line that is triggering the error
$("#help-email-form").ajaxSubmit({url: '/help/send_help_email', type: 'post', complete: handlerResponse })
This is complete block
var handlerResponse = function(data) {
alert(data);
};
$('#help-email-submit').live('click', function(e) {
$('#sender-email-wrapper').fadeOut('fast', function() {
$("#help-email-sent").fadeIn('slow');
});
$("#help-email-form").ajaxSubmit({url: '/help/send_help_email', type: 'post', complete: handlerResponse })
e.preventDefault();
});
$.fn.ajaxSubmiton the console give you?$.fn.ajaxSubmitreturns undefined<script>tag, and if it is after the jQuery<script>tag.