Submitting ajax form not working

Submitting ajax form not working

I'm trying to create a form that uses ajax. When I try to submit the form with no text then it alerts "no", which is right, but when I add a text and submit I still get an alert saying "no" instead of "yes".
  1. $("#contact_form").submit(function(e){ e.preventDefault(); var name = $("#name").val(); $form = $(this); $action = $form.attr('action'); var dataString = 'name='+name; $.ajax({ type: 'POST', url: $action+"/contact_request", data: dataString, dataType: 'json', encode : true }) .done(function(data) { alert('yes'); }) .fail(function(data){ alert('no'); }); });