通過AJAX和PHP,提交JQuery Mobile表單(兩篇)

來源:互聯網
上載者:User
通過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表單(兩篇),包括了方面的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.