PHP - AJAXLesson 79Free preview
AJAX XML
This lesson is part of PHP · All levels
Summary
AJAX responses don't have to be JSON, XML documents can also be sent by PHP and parsed on the client side. PHP sets the header of XML content and then displays the XML string, then the browser parses it using DOMParser to read each element. The choice between XML and JSON depends on the needs of the team's structure and convenience.
Key points
- PHP sends an XML response by setting the Content-Type: application/xml or text/xml.
- The browser parses the XML string using new DOMParser().
- The parsing results are read through getElementsByTagName() and textContent.
- JSON is more compact for JavaScript, XML is superior when it comes to requiring schema attributes and validation.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.