通过AJAX和PHP,提交JQuery Mobile表单(两篇)

2024-06-08 15:32

本文主要是介绍通过AJAX和PHP,提交JQuery Mobile表单(两篇),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

File name: callajax.php
[php] view plaincopy<?php  $firstName = $_POST[firstName];  $lastName = $_POST[lastName];  echo("First Name: " . $firstName . " Last Name: " . $lastName);  ?>  File name: index.php
[html] view plaincopy<!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进行页面跳转
[html] view plaincopy在CODE上查看代码片派生到我的代码片<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>  [html] view plaincopy在CODE上查看代码片派生到我的代码片<form method="post" id="feedbackform">  t;span style="white-space:pre">              </span>//相关表单元素  <input type="button" id="submitbtn" value="提交">  </form>  注意的是js里面的data
[html] view plaincopy在CODE上查看代码片派生到我的代码片$('#feedbackform').serialize()  是必须要有的,不然servlet里面用requset.getParameter接受的数据是null,ajax和后台成功交互后用changePage跳转到成功后显示的页面。
</pre><pre code_snippet_id="1849295" snippet_file_name="blog_20160824_1_2775332" name="code" class="html">
<dt style="list-style: none; word-break: break-all; word-wrap: break-word; margin: 0px; padding: 4px 0px 0px 7px; float: left; width: 77px; height: 60px; font-family: Verdana, 'Lucida Grande', Arial, Helvetica, sans-serif;"><a target=_blank href="http://my.csdn.net/" style="list-style: none; text-decoration: none; word-break: break-all; word-wrap: break-word; color: rgb(59, 89, 152); margin: 0px; padding: 0px;"><img src="http://avatar.csdn.net/2/A/1/3_u011447828.jpg" alt="u011447828" style="list-style: none; word-break: break-all; word-wrap: break-word; border: none; margin: 0px; padding: 0px; width: 48px; height: 48px;" /></a></dt><dd style="list-style: none; word-break: break-all; word-wrap: break-word; margin: 0px 0px 0px -10px; padding: 4px 0px 0px; float: left; width: 500px; font-family: Verdana, 'Lucida Grande', Arial, Helvetica, sans-serif;"><ul style="list-style: none; word-break: break-all; word-wrap: break-word; margin: 0px; padding: 0px;"><li class="user_name" style="list-style: none; word-break: break-all; word-wrap: break-word; margin: 0px; padding: 0px; font-stretch: normal; font-size: 14px; line-height: 24px; font-family: Arial, Helvetica, sans-serif;"><a target=_blank href="http://my.csdn.net/" class="user_name" style="list-style: none; text-decoration: none; word-break: break-all; word-wrap: break-word; color: rgb(68, 68, 68); margin: 0px 1em 0px 0px; padding: 0px; font-weight: bold; font-stretch: normal;">afterrains</a><span style="list-style: none; word-break: break-all; word-wrap: break-word; margin: 0px; padding: 0px; color: rgb(58, 156, 211);">别在熬夜了!</span></li><li class="feed_link" style="list-style: none; word-break: break-all; word-wrap: break-word; margin: 0px 0px 0px -5px; padding: 0px; color: rgb(170, 170, 170); font-stretch: normal; line-height: 24px; font-family: Arial, Helvetica, sans-serif;"><a target=_blank href="http://my.csdn.net/" style="list-style: none; text-decoration: none; word-break: break-all; word-wrap: break-word; color: rgb(7, 81, 154); margin: 0px 6px; padding: 0px;">个人主页</a>|<a target=_blank href="http://blog.csdn.net/u011447828" style="list-style: none; text-decoration: none; word-break: break-all; word-wrap: break-word; color: rgb(7, 81, 154); margin: 0px 6px; padding: 0px;">我的博客</a></li></ul></dd>

这篇关于通过AJAX和PHP,提交JQuery Mobile表单(两篇)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1042576

相关文章

HTML5中的Microdata与历史记录管理详解

《HTML5中的Microdata与历史记录管理详解》Microdata作为HTML5新增的一个特性,它允许开发者在HTML文档中添加更多的语义信息,以便于搜索引擎和浏览器更好地理解页面内容,本文将探... 目录html5中的Mijscrodata与历史记录管理背景简介html5中的Microdata使用M

html5的响应式布局的方法示例详解

《html5的响应式布局的方法示例详解》:本文主要介绍了HTML5中使用媒体查询和Flexbox进行响应式布局的方法,简要介绍了CSSGrid布局的基础知识和如何实现自动换行的网格布局,详细内容请阅读本文,希望能对你有所帮助... 一 使用媒体查询响应式布局        使用的参数@media这是常用的

HTML5表格语法格式详解

《HTML5表格语法格式详解》在HTML语法中,表格主要通过table、tr和td3个标签构成,本文通过实例代码讲解HTML5表格语法格式,感兴趣的朋友一起看看吧... 目录一、表格1.表格语法格式2.表格属性 3.例子二、不规则表格1.跨行2.跨列3.例子一、表格在html语法中,表格主要通过< tab

将Java项目提交到云服务器的流程步骤

《将Java项目提交到云服务器的流程步骤》所谓将项目提交到云服务器即将你的项目打成一个jar包然后提交到云服务器即可,因此我们需要准备服务器环境为:Linux+JDK+MariDB(MySQL)+Gi... 目录1. 安装 jdk1.1 查看 jdk 版本1.2 下载 jdk2. 安装 mariadb(my

Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案

《Vue3组件中getCurrentInstance()获取App实例,但是返回null的解决方案》:本文主要介绍Vue3组件中getCurrentInstance()获取App实例,但是返回nu... 目录vue3组件中getCurrentInstajavascriptnce()获取App实例,但是返回n

JS+HTML实现在线图片水印添加工具

《JS+HTML实现在线图片水印添加工具》在社交媒体和内容创作日益频繁的今天,如何保护原创内容、展示品牌身份成了一个不得不面对的问题,本文将实现一个完全基于HTML+CSS构建的现代化图片水印在线工具... 目录概述功能亮点使用方法技术解析延伸思考运行效果项目源码下载总结概述在社交媒体和内容创作日益频繁的

前端CSS Grid 布局示例详解

《前端CSSGrid布局示例详解》CSSGrid是一种二维布局系统,可以同时控制行和列,相比Flex(一维布局),更适合用在整体页面布局或复杂模块结构中,:本文主要介绍前端CSSGri... 目录css Grid 布局详解(通俗易懂版)一、概述二、基础概念三、创建 Grid 容器四、定义网格行和列五、设置行

前端下载文件时如何后端返回的文件流一些常见方法

《前端下载文件时如何后端返回的文件流一些常见方法》:本文主要介绍前端下载文件时如何后端返回的文件流一些常见方法,包括使用Blob和URL.createObjectURL创建下载链接,以及处理带有C... 目录1. 使用 Blob 和 URL.createObjectURL 创建下载链接例子:使用 Blob

Vuex Actions多参数传递的解决方案

《VuexActions多参数传递的解决方案》在Vuex中,actions的设计默认只支持单个参数传递,这有时会限制我们的使用场景,下面我将详细介绍几种处理多参数传递的解决方案,从基础到高级,... 目录一、对象封装法(推荐)二、参数解构法三、柯里化函数法四、Payload 工厂函数五、TypeScript

Vue3使用router,params传参为空问题

《Vue3使用router,params传参为空问题》:本文主要介绍Vue3使用router,params传参为空问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐... 目录vue3使用China编程router,params传参为空1.使用query方式传参2.使用 Histo