通过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 表单提交
最近在做手机页面用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");
- }
- });
- });
- });
- </script>
- <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表单的更多相关文章
- jQuery Mobile 表单基础
jQuery Mobile 会自动为 HTML 表单添加优异的便于触控的外观. jQuery Mobile 表单结构 jQuery Mobile 使用 CSS 来设置 HTML 表单元素的样式,以使其 ...
- (四)Jquery Mobile表单
Jquery Mobile表单与列表 一.JM表单 1.表单 普通html表单 效果: 2.只能输入数字的表单 效果: ...
- jquery mobile 表单提交 图片/文件 上传
jquerymobile 下面 form 表单提交 和普通html没区别,最主要是 <form 要加一个 data-ajax='false' 否则 上传会失败 1 html代码 <!do ...
- Jquery Mobile表单
三个前提: 1.每个form必须设置method和action属性 2.每个form必须有页面范围内唯一的id标识 3.每个form必须有一个label标签,通过设置它的for属性来匹配元素的id & ...
- jQuery Mobile 表单输入元素
jQuery Mobile 文本输入 输入字段是通过标准的 HTML 元素编写的,jQuery Mobile 会为它们设置专门针对移动设备的美观易用的样式.您还可以使用新的 HTML5 <inp ...
- ajax使用formdata 提交excel文件表单到rails解析
.modal-body .container-fluid .row .col-md-12 1.下载模板文件 = link_to '模板文件' .row .col-md-12 = form_tag '' ...
- 主攻ASP.NET MVC4.0之重生:Jquery Mobile 表单元素
相关代码: <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <tit ...
- jquery插件-表单提交插件-jQuery.Form
1.介绍 JQuery Form插件是一款强大的Ajax表单提交插件,可以简单方便的实现让我们的表单 由传统的提交方式转换成Ajax无刷新提交! 他提供了两个核心的方法ajaxForm以及ajaxSu ...
- jQuery Form 表单提交插件-----formSerialize,fieldSerialize,fieldValue,resetForm,clearForm,clearFields的 应用
一.jQuery Form的其他api 1. formSerialize 将表单序列化成查询串.这个方法将返回一个形如: name1=value1&name2=value2的字符串.是否可 ...
随机推荐
- C语言中的指针数组和数组指针
代码: #include <iostream> using namespace std; int main(){ ]; ]; cout<<sizeof(a)<<en ...
- Jquery 中 $('obj').attr('checked',true)失效的几种解决方案
转载自:搜狐博客 大拙无为 1.$('obj').prop('checked',true) 2. $(':checkbox').each(function(){ this.checked=true; ...
- jquery 自动实现autocomplete+ajax
来公司也差不多一个半月了,一直做点小东西,现在在做公司的出货系统,也只是做来锻炼锻炼的. 好了 不废话了 下面是实现 jquery插件 autocomplete+ajax 自动实现.也是刚学,勿喷. ...
- 做好织梦dedecms安全防护全部方法
很多同学遇到网站被攻击挂马,大都不是竞争对手所为.多数情况下是黑客利用工具批量扫描入侵的.因此安全防护自关重要. 织梦安装时注意: 修改默认数据库前缀: 在dedecms安装的时候修改下数据库的表前缀 ...
- 深入理解Azure自动扩展集VMSS(1)
前文中已经详细介绍了如何配置和部署Azure的虚拟机扩展集VMSS进行自动扩展,但在实际使用过程当中,用户会出现更进一步使用的一些问题,VMSS基本扩展原理及怎么简单调试?如何进行手动扩展?怎么使用自 ...
- 感知机(perceptron)
二类分类的线性分类模型,属于判别模型,利用梯度下降法对损失函数进行极小化求得感知机模型分为原始形式和对偶形式,是神经网络和支持向量机的基础 由输入控件到输出控件的如下函数: f(x)=sign(W.X ...
- LeetCode_Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...
- Source Insight设置总结
在网上搜索了一些关于Source Insight的设置技巧,把这些结果给总结下来: 1. 背景色选择 要改变背景色Options->preference->windows backgrou ...
- Web模板大全
http://www.dede58.com/a/free/ http://down.admin5.com/moban/109507.html http://www.chinaz.com/ http:/ ...
- js深入研究之类定义与使用
js可以定义自己的类 很有意思 <script type="text/javascript"> var Anim = function() { alert('nihao ...