使用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>@@##@@</h1> </div> <!-- /header --> <div data-role="content"> <div class="content-primary"> <p></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/xiazai/code/10638">
<img src="https://img.php.cn/upload/webcode/000/000/005/176309820356916.png" alt="ECTouch移动商城系统">
</a>
<div class="aritcle_card_info">
<a href="/xiazai/code/10638">ECTouch移动商城系统</a>
<p>ECTouch是上海商创网络科技有限公司推出的一套基于 PHP 和 MySQL 数据库构建的开源且易于使用的移动商城网店系统!应用于各种服务器平台的高效、快速和易于管理的网店解决方案,采用稳定的MVC框架开发,完美对接ecshop系统与模板堂众多模板,为中小企业提供最佳的移动电商解决方案。ECTouch程序源代码完全无加密。安装时只需将已集成的文件夹放进指定位置,通过浏览器访问一键安装,无需对已有</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="ECTouch移动商城系统">
<span>0</span>
</div>
</div>
<a href="/xiazai/code/10638" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="ECTouch移动商城系统">
</a>
</div>
<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><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> <p></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</p> </div> </div> <a id="mylogin" href="javascript:void(0);" data-role="button" data-theme="e" data-icon="check">登录系统</a> <p>@@##@@</p> <p></p><p><span>立即学习</span>“<a href="https://pan.quark.cn/s/7fc7563c4182" style="text-decoration: underline !important; color: blue; font-weight: bolder;" rel="nofollow" target="_blank">PHP免费学习笔记(深入)</a>”;</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文件<?phpfunction 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

PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号