Check JSON string from AJAX response with jQuery -


i've using jquery on contact form web app we're building, getting json response server is:

{"success": true} 

here's jquery far:

$('.contact-form').on('submit', function(e) {              // prevent submitting             e.preventdefault();              // loading data-* attr             var $submit = $('#contact-submit');             $submit.html($submit.data('text'));              // form data             var form      = $(this);             var post_url  = form.attr('action');             var post_data = form.serialize();              // ajax call             $.ajax({                 type    : 'post',                 url     : post_url,                 data    : post_data,                 datatype: 'json',                 success: function(){                  },                 error: function(){                  }             });          }); 

i've hit wall i've never 'checked' against json response before in 'success' jquery method, can on this? looking method of checking response i'm getting, , if 'true' presented, show 'sent success' message.

the success callback json object first parameter, can use in callback shown below

$.ajax({     type : 'post',     url : post_url,     data : post_data,     datatype : 'json',     success : function(data) {         if(data.success){             //do if success         }      },     error : function() {      } }); 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -