image.png
// json
('#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');
}
});
});
Demo 8 : form插件的使用--dataType的其他方式.
json方式返回
名称:
地址:
自我介绍:
xml方式返回
名称:
地址:
自我介绍:
html方式返回
名称:
地址:
自我介绍: