PHP and AJAX: How to send/handle error responses?

dx2

New Member
There are 3 elements to this.
  • An HTML form
  • The AJAX connection which sends the form values and receives and parses response from the PHP script
  • The PHP script which decides whether the values are good/bad or not and sends back an appropriate response (probably in XML format for easy parsing by the javascript function?)
When the PHP looks at and handles the sent data, inserting it into a database or doing whatever with it, it needs to send back a response or maybe a collection of responses so that javascript can display a proper error message(s) to the user. Maybe also putting a red border or something around the elements that have the bad input.How is this usually done, on both ends? I'm thinking that PHP should just send back simple numeric error codes and javascript will set the proper text error messages in different divs. But I'm not really sure, and I'm not really sure what I should be googling to find an answer.(BTW I'm not talking about HTTP error codes)
 
Back
Top