title: How to display error messages Jquery ajax?
body: <p>I am a student and am using jquery and php to add records to database. Records are being added, but i want to display a message "Record inserted" in the  if the the record has been successfully been added and an error message if an error occurs.</p>
  
  <p>This is my html code:</p>
  
  <pre><code>&lt;form id="forn-newsletter" class="form-horizontal" method="POST"&gt;
  &lt;div class="form-group"&gt;
      &lt;label id="name_label" class="control-label col-xs-2"&gt;Name&lt;/label&gt;
      &lt;div class="col-xs-10"&gt;
          &lt;input type="text" class="form-control" id="news_name" name="news_name" placeholder="Name" onblur="checkName();"/&gt;&lt;font color="red"  id="name_error"&gt;&lt;/font&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
      &lt;label id="email_label" class="control-label col-xs-2"&gt;Email&lt;/label&gt;
      &lt;div class="col-xs-10"&gt;
          &lt;input type="text" class="form-control" id="news_email" name="news_email" placeholder="Email" onblur="vali()"/&gt;&lt;font color="red"  id="email_error"&gt;&lt;/font&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
      &lt;div class="col-xs-offset-2 col-xs-10"&gt;
          &lt;button id="register-newsletter" type="submit" class="btn btn-primary"&gt;Register for Newsletter&lt;/button&gt;
  
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div id="dialog"&gt;&lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>This is my registration-newsletter.php</p>
  
  <pre><code>&lt;?php
  include('connect.php');
  
  $name=$_POST['name'];
  $email=$_POST['email'];
  $val=md5($name.$email);
  $query = "INSERT INTO newsletter (Id,Name,Email,Val) VALUES('','$name','$email','$val')";
  
  
  $result=mysql_query($query);
  if(!$result){
      echo "Some error Occured..Please try later";
  }
  else{
      echo "Your details have been saved. Thank You ";
  }
  
  mysql_close($con);
  ?&gt;
  </code></pre>
  
  <p>This is my JQuery code </p>
  
  <pre><code>$(document).ready(function(){
  $("#register-newsletter").click(function(){
      var name=$("#news_name").val();
      var email=$("#news_email").val();
  
      var dataString="name="+name+"&amp;email="+email;
      var request;
          request = $.ajax({
          url: "registration-newsletter.php",
          type: "POST",           
          data: dataString
          });
  
      //return false;
  });
  
  });
  </code></pre>