废话不多说了,直接给大家贴代码了,具体代码如下所示:
<title>jQuery form插件的使用--处理server返回的JSON, XML,HTML数据</title><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><script src="jquery-1.3.1.js" type="text/javascript"></script><script src="jquery.form.js" type="text/javascript"></script><script type="text/javascript">
// json
$(document).ready(function() {
$('#myForm').ajaxForm({
// 声明 服务器返回数据的类型.
dataType: 'json',
success: processJson
});
});
function processJson(data) {
// 'data'是一个json对象,从服务器返回的.
$('#jsonOut').html(data.name + " "+data.address + " "+data.comment);
}
// xml
$(document).ready(function() {
$('#xmlForm').ajaxForm({
// 声明 服务器返回数据的类型.
dataType: 'xml',
success: processXml
});
});
function processXml(responseXML) {
// 'responseXML' 是一个XML的文档 ,从服务器返回的.
var name = $('name', responseXML).text();
var address = $('address', responseXML).text();
var comment = $('comment', responseXML).text();
$('#xmlOut').html(name + " "+address + " "+comment);
}
// html
$(document).ready(function() {
$('#htmlForm').ajaxForm({
// 用服务器返回的数据 更新 id为 htmlcssrain 的内容.
target: '#htmlOut',
success: function() {
$('#htmlOut').fadeIn('slow');
}
});
});
</script><h3> Demo 8 : jQuery form插件的使用--处理server返回的JSON, XML,HTML数据</h3>
<!-- demo1 json-->
<h4>json方式返回</h4>
xml方式返回
html方式返回
新建json.jsp文件:
新建xml.jsp文件:
");
out.print("<root>");
out.print("<name>"+name+"</name>");
out.print("<address>"+address+"</address>");
out.print("<comment>"+comment+"</comment>");
out.print("</root>");
%>
新建一个html.jsp文件:
"+name+" "+address+" "+comment+"
以上所述是小编给大家分享的jQuery form插件的使用之处理server返回的JSON, XML,HTML数据,希望对大家有所帮助。
前端入门到VUE实战笔记:立即使用
在学习笔记中,你将探索 前端 的入门与实战技巧!










