前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >jquery ajaxform插件

jquery ajaxform插件

作者头像
用户5760343
发布2019-10-10 14:33:30
8.2K0
发布2019-10-10 14:33:30
举报
文章被收录于专栏:sktjsktj

image.png

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html> <head> <title></title> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <script src="../../scripts/jquery.js" type="text/javascript"></script> <script src="lib/jquery.form.js" type="text/javascript"></script> <script type="text/javascript"> // json

(document).ready(function() {
(document).ready(function() {

('#myForm').ajaxForm({ // 声明 服务器返回数据的类型. dataType: 'json', success: processJson }); });

代码语言:javascript
复制
                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> </head>

<body> <h3> Demo 8 : form插件的使用--dataType的其他方式. </h3> <h4>json方式返回</h4> <form id="myForm" action="json.php" method="post"> 名称: <input type="text" name="name" id="name" /> 地址: <input type="text" name="address" id="address"/> 自我介绍: <textarea name="comment" id="comment" ></textarea> <input type="submit" id="test" value="json方式返回" /> <div id="jsonOut" ></div> </form>

<h4>xml方式返回</h4> <form id="xmlForm" action="xml.php" method="post"> 名称: <input type="text" name="xmlname" id="xmlname" /> 地址: <input type="text" name="xmladdress" id="xmladdress"/> 自我介绍: <textarea name="xmlcomment" id="xmlcomment" ></textarea> <input type="submit" id="xmltest" value="xml方式返回" /> <div id="xmlOut" ></div> </form>

<h4>html方式返回</h4> <form id="htmlForm" action="html.php" method="post"> 名称: <input type="text" name="htmlname" id="htmlname" /> 地址: <input type="text" name="htmladdress" id="htmladdress"/> 自我介绍: <textarea name="htmlcomment" id="htmlcomment" ></textarea> <input type="submit" id="htmltest" value="html方式返回" /> <div id="htmlOut" ></div> </form> </body> </html>

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019.10.09 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档