Ajax accesses the xml file code instance, and ajax accesses the xml instance
Ajax access to the xml file code instance:
Xml files are still frequently used. The following is an example code that uses jquery ajax to access xml files. It is very simple and I hope it can help my friends who need it, the code example is as follows:
I. ajax code:
$. Ajax ({url :'... ', type: 'post', ype: 'xml', error: function (xml) {alert ("Error loading xml document" + XML);}, success: function (xml) {$ (xml ). find ("X "). each (function (I) {alert ($ (this ). attr ("Xattr "));});}});
Ii. Background code:
Public ActionForward execute (ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {response. setContentType ("text/xml; charset = UTF-8"); response. setCharacterEncoding ("UTF-8"); PrintWriter pw = response. getWriter (); Document doc = new Document (); // get the XML file doc. write (pw); return null ;}
The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 10640.
For more information, see: http://www.softwhy.com/jquery/