通过ajax和php,提交jquery mobile表单
file name: callajax.php
<?php  
    $firstname = $_post[firstname];  
    $lastname = $_post[lastname];  
       
    echo("first name: " . $firstname . " last name: " . $lastname);  
?>
file name: index.php
<!doctype html>  
<html>  
    <head>  
    <title>submit a form via ajax</title>  
      <link rel="stylesheet" href="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.css" />  
      <script src="http://code.jquery.com/jquery-1.5.2.min.js"></script>  
      <script src="http://code.jquery.com/mobile/1.0a4/jquery.mobile-1.0a4.min.js"></script>  
</head>  
<body>  
    <script>  
        function onsuccess(data, status)  
        {  
            data = $.trim(data);  
            $("#notification").text(data);  
        }  
    
        function onerror(data, status)  
        {  
            // handle an error  
        }          
    
        $(document).ready(function() {  
            $("#submit").click(function(){  
    
                var formdata = $("#callajaxform").serialize();  
    
                $.ajax({  
                    type: "post",  
                    url: "callajax.php",  
                    cache: false,  
                    data: formdata,  
                    success: onsuccess,  
                    error: onerror  
                });  
    
                return false;  
            });  
        });  
    </script>  
    
    <!-- call ajax page -->  
    <div data-role="page" id="callajaxpage">  
        <div data-role="header">  
            <h1>call ajax</h1>  
        </div>  
    
        <div data-role="content">  
            <form id="callajaxform">  
                <div data-role="fieldcontain">  
                    <label for="firstname">first name</label>  
                    <input type="text" name="firstname" id="firstname" value=""  />  
   
                    <label for="lastname">last name</label>  
                    <input type="text" name="lastname" id="lastname" value=""  />  
                    <h3 id="notification"></h3>  
                    <button data-theme="b" id="submit" type="submit">submit</button>  
                </div>  
            </form>  
        </div>  
    
        <div data-role="footer">  
            <h1>giantflyingsaucer</h1>  
        </div>  
    </div>  
</body>  
</html>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
jquery mobile 表单提交
http://blog.csdn.net/tjpu_lin/article/details/28394253
最近在做手机页面用jquery mobile开发,在用到form表单提交到时遇到了问题。
后台是用servlet进行处理的,想通过servlet里面的重定向进行页面跳转发现在手机上根本没有用,出现errorpage提示信息。
查询网上资料以及jquery mobile api得知 jquery mobile表单提交默认是ajax提交,所以页面跳转写在servlet里面根本就不会实现页面跳转功能。
于是我按照教程在form里面加了  data-ajax=“false”这一属性,发现别说是页面跳转不行,就连后台的数据库操作都做不了,报了500错误。
想了好久既然用ajax提交,那么就用ajax进行页面跳转
<script type="text/javascript">  
        $(document).ready(function () {  
            $("#submitbtn").click(function(){  
                    cache: false,  
                    $.ajax({  
                      type: "post",  
                      url: "feedback",  
                      data: $('#feedbackform').serialize(),  
                      success:function(data){  
                            $.mobile.changepage("success.html");  
                      }  
                });  
            });  
  
        });
<form method="post" id="feedbackform">  
t;span style="white-space:pre">              </span>//相关表单元素  
    <input type="button" id="submitbtn" value="提交">  
</form>
注意的是js里面的data
$('#feedbackform').serialize()
是必须要有的,不然servlet里面用requset.getparameter接受的数据是null,ajax和后台成功交互后用changepage跳转到成功后显示的页面。
以上就介绍了通过ajax和php,提交jquery mobile表单(两篇),包括了方面的内容。
   
 
   