artdvp
9/9/2017 - 4:12 PM

Rest API Javascript

render status: 200, json: { response: { data: data }, success: true }
render status: 400, json: { response: { data: data }, success: false }
code = { 
  success: 200,
  bad_request: 400,
  unauthorized: 401,
  forbidden: 403,
  not_found: 404,
  internal_server_error: 500,
  bad_gateway: 502,
  service_unavailable: 503 
  }
 $.ajax({ url: '127.0.0.1/aritcles/1',
         dataType: 'json',
         type: "GET",
         success: function(data, textStatus, xhr) {
          // this line will show true or false depen on server response
          alert(data.success);
         },
         error: function(xhr, textStatus, errorThrown) {
          // this line no longer user beacase ervery response is 200
          // data.success gose to undefined 
          alert(data.success);
         }
   });