The examples in this article describe jquery parsing and processing methods for server-side return XML format data. Share to everyone for your reference, specific as follows:
1.php Code:
<?php
Header ("Content-type:text/xml; Charset=utf-8 ")//Declaration browser-side return data format is XML document Format
echo" <?xml version= ' 1.0 ' encoding= ' utf-8 '?> ' ".
" <comments> ".
" <comment username= ' {$_request[' username ']} ' > '.
<content>{$_request[' content ']}</content> '.
" </comment> ".
" </comments> ";
? >
2.html Code:
<form id= "Form1" action= "#" >
<p> comments:</p>
<p> name: <input type= "text" name= "username "id=" username "/></p>
<p> Contents: <textarea name=" Content "id=" Content "rows=" 2 "cols=" ></" textarea></p>
<p><input type= "button" id= "send" value= "submit"/></p>
</form>
<div class= ' comment ' > has commented:</div>
<div id= "ResText" ></div>
3.jQuery Code:
<script src= "Jquery-1.3.1.js" type= "Text/javascript" ></script> <script type= "Text/javascript" >/* 1. Because the data format returned by the server side is an XML document, the returned data needs to be processed, and the jquery processing XML documents can also use the regular attr (), find (), filter (), and other method 2. The process of returning a data format to an XML document is a little more complex than an HTML fragment, but the portability of XML documents is unmatched by other data formats, so the reusability of the data provided in this format can be significantly increased by 3. Many well-known web sites and open platforms are outputting data in XML format, Collaborators can use the APIs they provide to integrate the content into their own web site 4.xml documents are relatively large in size, and they are slower to parse and manipulate than other file formats 5. Because you expect the data format returned by the server side to be an XML document,
Therefore, you need to set the Content-type type on the server side, such as header ("Content-type:text/xml;charset=utf-8"); */$ (function () {$ ("#send"). Click (function () {$.get ("get2.php", {username: $ ("#username"). Val (), Conte
NT: $ ("#content"). Val ()}, function (data, textstatus) {//data:xml format; Find the value of the comment element Username property from data in XML format var username = $ (data). Find ("comment"). attr ("username");//To parse HTML document like var content = $ (data). Find ("Comment con
Tent "). Text (); var txthtml = "<div class= ' comment ' >
More interested readers of jquery related content can view the site topics: "jquery Operation XML Skills Summary", "JQuery Extended Skills Summary", "jquery common Plug-ins and Usage summary", "jquery drag and drop effects and tips summary", "jquery Table" ( Table) Summary of operational techniques, "Summary of Ajax usage in jquery", "jquery common Classic Effects Summary", "jquery animation and special effects usage Summary" and "jquery Selector usage Summary"
I hope this article will help you with the jquery program design.