使用Rexsee、Jquery、PHP开发移动应用中的数据交互有关问题
使用Rexsee、Jquery、PHP开发移动应用中的数据交互问题
?
Rexsee社区的一篇经验贴,转过来,主要是介绍数据交互这一块的实现,共同学习:
?
在开发某移动销售产品时,用户要求通过WebService调用进行数据交互。使用Rexsee,Jquery-mobile,PHP,WebService几种开发工具可以做到设备调用完成照片、定位等功能,使用Juqery-mobile开发界面,使用PHP+SOAP完成数据库及Webservice的数据交互功能,通过JSON使用PHP将返回数据封装后再返回到前端,这样就做到了数据的异步交互,而且返回结果标准统一,可用性强。下面通过几个例子介绍一下:
登录页面:
?
?
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312" /> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>移动销售</title> <link rel="stylesheet" href="../m_jquery-110/jquery.mobile-1.1.0.css" /> <link rel="stylesheet" href="../m_jquery-110/demos/docs/_assets/css/jqm-docs.css"/> <script src="../m_jquery-110/demos/js/jquery.js"></script> <script src="../m_jquery-110/demos/docs/_assets/js/jqm-docs.js"></script> <script src="../m_jquery-110/jquery.mobile-1.1.0.js"></script> <script src="../m_jquery/demos/jquery.json-2.3.js"></script> <STYLE type=text/css> .dotline { BORDER-BOTTOM-STYLE: dotted; BORDER-LEFT-STYLE: dotted; BORDER-RIGHT-STYLE: dotted; BORDER-TOP-STYLE: dotted; color:#FFCCFF } </STYLE> <script type="text/javascript"> function getCookie(name) { var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)")); if(arr != null) return unescape(arr[2]); return false; } function SetCookie(name,value) { var Days = 30; var exp = new Date(); exp.setTime(exp.getTime() + Days*24*60*60*1000); document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); return false; } function onError(data, status) { alert("获取数据失败"); rexseeApplication.quit(); return false; } function onSuccess(data, status) { if (status="sucess") //alert("刷新数据成功!"); mk_data(data,status); return false; } function mk_data(data,status) { data = $.trim(data); //alert(data); var m_sel = $.evalJSON(data).Shop.oper; //alert(m_sel); if (m_sel=="getshop") { if (data=="{}") { alert("登录失败,系统将退出!"); rexseeApplication.quit(); } else { var data1 = $.evalJSON(data).Shop.shopno; var data2 = $.evalJSON(data).Shop.shopname; //alert(data1); var data3 = $("#uname").val(); var data4 = $("#upwd").val(); var m_txt="欢迎您"+ data3 + "\n 部门:" + data1 + data2; alert(m_txt); if (data1!="") { SetCookie("uname", data3); SetCookie("ushopno", data1); SetCookie("ushopname", data2); SetCookie("upwd", data4); //window.open ('main.php'); window.location="main.php"; } } } return false; } function init() { var m_v1=$("#uname").val(); var m_v2=$("#upwd").val(); if (m_v1=="") { alert("请输入号码!"); return false; } if (m_v2=="") { alert("请输入密码!"); return false; } $("#oper").val('getshop'); var formData = $("#loginForm").serialize(); $.ajax({ type: "POST", url: "func_soap.php", cache: false, data: formData, success: onSuccess, error: onError }); return false; } $(document).ready(function() { rexseeScreen.setScreenOrientation('portrait'); rexseeStatusBar.setStyle('visibility:hidden;'); var m_s1=rexseeTelephony.getDeviceId(); var m_s2=getCookie('uname'); var m_s3=getCookie('upwd'); $("#uname").val(m_s2); $("#upwd").val(m_s3); $("#mylogin").click(function(){ //alert("fdjsaf"); init(); }) return false; }); </script> </head> <body> <form name="loginForm" id="loginForm" method="POST" target="_self" action="javascript:void(0);" > <input type="hidden" name="oper" id="oper" size="36" value="" readonly> <div data-role="page" class="type-interior" id="album-list"> <div data-role="header" class="footer-docs" data-theme="b"> <h1><img src="/static/imghw/default1.png" data-src="images/logo4.png" class="lazy" / alt=" 使用Rexsee、Jquery、PHP开发移动应用中的数据交互有关问题 " ></h1> </div> <!-- /header --> <div data-role="content"> <div class="content-primary"> <p></p> <div class="ui-body ui-body-c"> <div class='ui-grid-a' id=saleinfo> <div class='ui-block-a' style='width:180px'><label for='dd_sid'>手机号码</label></div><div class='ui-block-b'></div> <div class='ui-block-a' style='width:180px'><input type='text' name='uname' id='uname' value='18658269081' /></div><div class='ui-block-b'></div> <div class='ui-block-a' style='width:180px'><label for='dd_sid'>登录密码</label></div><div class='ui-block-b'></div> <div class='ui-block-a' style='width:180px'><input type='password' name='upwd' id='upwd' value='' /></div><div class='ui-block-b'></div> <p></p> <p></p> </div> </div> <a id="mylogin" href="javascript:void(0);" data-role="button" data-theme="e" data-icon="check">登录系统</a> <p><img src="/static/imghw/default1.png" data-src="images/back.png" class="lazy" border="0" alt=" 使用Rexsee、Jquery、PHP开发移动应用中的数据交互有关问题 " ></p> <p></p> </div> </div><!-- /content --> <div data-role="footer" class="footer-docs" data-theme="b" data-position="fixed"> <p>CopyRight© Chinaunicom Jinan 2012 All Right Reserved. </p> </div> </div><!-- /page --> </form> </body> </html>
?
以上页面通过Jquery-mobile显示一个登录页面,点击提交后异步调用func_sap函数完成WebSerivce调用及返回,返回数据以JSON形式,通过javascript的json函数将数据提取并处理。
func_soap.php文件 <?php function getshop($phone) { $wsdl = "http://.../Service.asmx?wsdl"; $soap_client = new SoapClient($wsdl); $param=array( 'phone'=> $phone); $objectresult = $soap_client->AgetShop($param); $simpleresult = $objectresult->AgetShopResult; $obj = simplexml_load_string($simpleresult); $obj->Shop[0]->addChild("oper", "getshop"); $json = json_encode($obj); $array = json_decode($json,TRUE); $_SESSION['shopno']= $array["Shop"]['shopno']; $_SESSION['phone']=$phone; return $json; } //调用函数 header("Content-Type:text/html;charset=utf-8"); $moper=$_POST['oper']; if ($moper=="getshop") { $mresult=getshop($muname); echo $mresult; } ?>
?原文链接:http://www.rexsee.com/CN/bbs/thread/2012-04-29/556.html

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Detailed explanation of jQuery reference method: Quick start guide jQuery is a popular JavaScript library that is widely used in website development. It simplifies JavaScript programming and provides developers with rich functions and features. This article will introduce jQuery's reference method in detail and provide specific code examples to help readers get started quickly. Introducing jQuery First, we need to introduce the jQuery library into the HTML file. It can be introduced through a CDN link or downloaded

How to use PUT request method in jQuery? In jQuery, the method of sending a PUT request is similar to sending other types of requests, but you need to pay attention to some details and parameter settings. PUT requests are typically used to update resources, such as updating data in a database or updating files on the server. The following is a specific code example using the PUT request method in jQuery. First, make sure you include the jQuery library file, then you can send a PUT request via: $.ajax({u

How to remove the height attribute of an element with jQuery? In front-end development, we often encounter the need to manipulate the height attributes of elements. Sometimes, we may need to dynamically change the height of an element, and sometimes we need to remove the height attribute of an element. This article will introduce how to use jQuery to remove the height attribute of an element and provide specific code examples. Before using jQuery to operate the height attribute, we first need to understand the height attribute in CSS. The height attribute is used to set the height of an element

Title: jQuery Tips: Quickly modify the text of all a tags on the page In web development, we often need to modify and operate elements on the page. When using jQuery, sometimes you need to modify the text content of all a tags in the page at once, which can save time and energy. The following will introduce how to use jQuery to quickly modify the text of all a tags on the page, and give specific code examples. First, we need to introduce the jQuery library file and ensure that the following code is introduced into the page: <

Title: Use jQuery to modify the text content of all a tags. jQuery is a popular JavaScript library that is widely used to handle DOM operations. In web development, we often encounter the need to modify the text content of the link tag (a tag) on the page. This article will explain how to use jQuery to achieve this goal, and provide specific code examples. First, we need to introduce the jQuery library into the page. Add the following code in the HTML file:

How to tell if a jQuery element has a specific attribute? When using jQuery to operate DOM elements, you often encounter situations where you need to determine whether an element has a specific attribute. In this case, we can easily implement this function with the help of the methods provided by jQuery. The following will introduce two commonly used methods to determine whether a jQuery element has specific attributes, and attach specific code examples. Method 1: Use the attr() method and typeof operator // to determine whether the element has a specific attribute

jQuery is a popular JavaScript library that is widely used to handle DOM manipulation and event handling in web pages. In jQuery, the eq() method is used to select elements at a specified index position. The specific usage and application scenarios are as follows. In jQuery, the eq() method selects the element at a specified index position. Index positions start counting from 0, i.e. the index of the first element is 0, the index of the second element is 1, and so on. The syntax of the eq() method is as follows: $("s

jQuery is a popular JavaScript library widely used in web development. During web development, it is often necessary to dynamically add new rows to tables through JavaScript. This article will introduce how to use jQuery to add new rows to a table, and provide specific code examples. First, we need to introduce the jQuery library into the HTML page. The jQuery library can be introduced in the tag through the following code:
