这里的话是mui框架传值问题,使用mui的frie实现传值跳转页面
mui.fire()触发自定义事件\_HBuilder教程\_B5教程网 // JavaScript Document //检查是否为移动客户端访问。pad除外。返回1为是。返回0为否 function cmobile(){ if(/AppleWebKit.\*Mobile/i.test(navigator.userAgent) || (/MIDP|SymbianOS|NOKIA|SAMSUNG|LG|NEC|TCL|Alcatel|BIRD|DBTEL|Dopod|PHILIPS|HAIER|LENOVO|MOT-|Nokia|SonyEricsson|SIE-|Amoi|ZTE/.test(navigator.userAgent))){ if(window.location.href.indexOf("?mobile")<0){ try{ if(/Android|Windows Phone|webOS|iPhone|iPod|BlackBerry/i.test(navigator.userAgent)){ return 1; }else if(/iPad/i.test(navigator.userAgent)){ return 0; }else{ return 1; } }catch(e){} } } } if(cmobile()) { var webUrl = document.location.href; str=webUrl.replace("www","m"); window.location.href=str; } $(function(){ $("img.pic1").lazyload(); }) img.pic1{ -ms-interpolation-mode: bicubic; } #cas { position: fixed; top: 0; left: 0; z-index: -1; opacity: .5 }
**监听自定义事件**
添加自定义事件监听操作和标准js事件监听类似,可直接通过window对象添加,如下:
window.addEventListener('customEvent',function(event){
//通过event.detail可获得传递过来的参数内容
....
});
**触发自定义事件**
通过mui.fire()方法可触发目标窗口的自定义事件
目标webview必须触发loaded事件后才能使用自定义事件
若新创建一个webview,不等该webview的loaded事件发生,就立即使用webview.evalJS()或mui.fire(webview,'eventName',{}),则可能无效
### 示例
假设如下场景:从新闻列表页面进入新闻详情页面,新闻详情页面为共用页面,通过传递新闻ID通知详情页面需要显示具体哪个新闻,详情页面再动态向服务器请求数据,mui要实现类似需求可通过如下步骤实现:
* 在列表页面中预加载详情页面(假设为detail.html)
* 列表页面在点击新闻标题时,首先,获得该新闻id,触发详情页面的newsId事件,并将新闻id作为事件参数传递过去;然后再打开详情页面;
* 详情页面监听newsId自定义事件
列表页面代码如下:
~~~
//初始化预加载详情页面
mui.init({
preloadPages:[{
id:'detail.html',
url:'detail.html'
}
]
});
var detailPage = null;
//添加列表项的点击事件
mui('.mui-content').on('tap', 'a', function(e) {
var id = this.getAttribute('id');
//获得详情页面
if(!detailPage){
detailPage = plus.webview.getWebviewById('detail.html');
}
//触发详情页面的newsId事件
mui.fire(detailPage,'newsId',{
id:id
});
//打开详情页面 www.bcty365.com
mui.openWindow({
id:'detail.html'
});
});
~~~
详情页面代码如下:
~~~
//添加newId自定义事件监听
window.addEventListener('newsId',function(event){
//获得事件参数
var id = event.detail.id;
//根据id向服务器请求新闻详情
.....
});
~~~
这个意思大概是先在前面使用init定义好需要跳转的页面,也就是预加载,然后再通过监听动作来触发相应的处理,把id传值过去,打开页面。对应页面获取传值就行了。
![](https://box.kancloud.cn/719b0cfe7c1c769483a89bd92f581489_818x893.png)
![](https://box.kancloud.cn/ea4046a79c6cebe97cfd9385a0b25e01_818x841.png)
![](https://box.kancloud.cn/f160dfaf10f4035a36762cb9c12ffdd2_843x522.png)
![](https://box.kancloud.cn/dfa0baaccbc5aaf85ac6c1c1359698c3_817x895.png)
![](https://box.kancloud.cn/63031643bd67d67cd216f80ad07a92c5_658x409.png)
![](https://box.kancloud.cn/8f570b5927ea0e3808c18387aed8e8cd_845x913.png)
![](https://box.kancloud.cn/941f12d09c2fb4cd9232109af2cf35b6_812x636.png)
![](https://box.kancloud.cn/c3267d98c1ca2a508ab9917b8b82517a_781x429.png)
![](https://box.kancloud.cn/38224411fc224b45af88e3e0b48a0857_861x584.png)
![](https://box.kancloud.cn/2c1f7d5363774d052a123e9833830547_830x888.png)
mui的图片上传实例:
<body>
<header class="mui-bar mui-bar-nav" style="height: ;">
<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
<h1 class="mui-title">发表评价</h1>
</header>
<!-- 多行文本框 -->
<div class="mui-input-row" style="margin: 70px 10px;">
<textarea rows="5" placeholder="请对本次服务做出评价吧!"></textarea>
</div>
<!-- 星级评价 -->
<div id="star" data-score="1"></div>
<!-- 图片上传 -->
<a class="imageup 1" id="headImage"><img id="headimg" class="headimg" src='' onerror="this.src='images/scimg.png'" alt="点击上传图片" border="2" height="100" width="100">
</a>
<a class="imageup 2" id="uploadImage"><img id="headimg" class="headimg" src='' onerror="this.src='images/scimg.png'" height="100" width="100">
</a>
<!-- <p><button id="uploadImage" class='button'> 提交</button></p> -->
<div class="mui-content" style="background-color:#fff">
<ul id="imgs" class="mui-table-view mui-grid-view">
</ul>
</div>
<script src="js/mui.min.js"></script>
<script src="js/app.js"></script>
<script src="js/mui.zoom.js"></script>
<script src="js/mui.previewimage.js"></script>
<script src="js/host.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.raty.min.js"></script>
<script>
window.addEventListener('newsId',function(event){
//获得事件参数
var user_id = event.detail.id;
var shop_id = event.detail.shop_id;
});
var state = app.getState();
var user_id = state.user_id;
// 获取商品和个人id
C1=window.location.href.split("?")[1];
C2=C1.split("=")[1];
var shop_id = C2;
alert(shop_id); alert(user_id);
//星级评价代码
$.fn.raty.defaults.path = 'js/img';
$('#star').raty();
$('#score-demo').raty({
score: 3
});
// 图片上传代码
//扩展API完成后执行的操作
var fileArr = [];
mui.init({
swipeBack: true //启用右滑关闭功能
});
document.getElementById('headImage').addEventListener('tap', function() {
if(mui.os.plus) {
var buttonTit = [{
title: "拍照"
}, {
title: "从手机相册选择"
}];
plus.nativeUI.actionSheet({
title: "上传图片",
cancel: "取消",
buttons: buttonTit
}, function(b) { /*actionSheet 按钮点击事件*/
switch(b.index) {
case 0:
break;
case 1:
getImage(); /*拍照*/
break;
case 2:
galleryImg(); /*打开相册*/
break;
default:
break;
}
})
}
}, false);
// 拍照获取图片
function getImage() {
var c = plus.camera.getCamera();
c.captureImage(function(e) {
plus.io.resolveLocalFileSystemURL(e, function(entry) {
var imgSrc = entry.toLocalURL() + "?version=" + new Date().getTime(); //拿到图片路径
setFile(imgSrc);
setHtml(imgSrc);
}, function(e) {
console.log("读取拍照文件错误:" + e.message);
});
}, function(s) {
console.log("error" + s.message);
}, {
filename: "_doc/camera/"
})
}
// 从相册中选择图片
function galleryImg() {
// 从相册中选择图片
plus.gallery.pick(function(e) {
for(var i in e.files) {
var fileSrc = e.files[i];
setFile(fileSrc);
setHtml(fileSrc);
}
}, function(e) {
console.log("取消选择图片");
}, {
filter: "image",
multiple: true,
//maximum: 5,
system: false,
onmaxed: function() {
plus.nativeUI.alert('最多只能选择5张图片');
}
});
}
function setHtml(path) {
var str = '';
str = '<li class="mui-table-view-cell mui-media mui-col-xs-6">'+
'<img class="mui-media-object" src="'+path+'">'+
'<span class="mui-icon mui-icon-trash deleteBtn"></span>'+
'</li>';
jQuery("#imgs").append(str);
}
function setFile(fileSrc){
var image = new Image();
image.src = fileSrc;
fileArr.push(image);
}
document.getElementById('uploadImage').addEventListener('tap',function(){
var files = fileArr;
var wt=plus.nativeUI.showWaiting();
var task=plus.uploader.createUpload('http://'+host+'/heutoi/evaluate.php',
{method:"POST",priority:100},
function(t,status){ //上传完成
if(status==200){
alert("图片上传成功");
wt.close(); //关闭等待提示按钮
}else{
alert("上传失败:"+status);
wt.close();//关闭等待提示按钮
}
}
);
//将文件集合添加到上传队列中
for(var i=0;i<files.length;i++){
var f=files[i];
task.addFile(f.src,{key:i});
}
//传其他的参数 如备注
//添加其他参数
//遍历5个input框
task.addData("comment","test");
task.start();
});
php接收图片保存代码:
~~~
<?php
//判断表单提交方式,post提交
if($_SERVER['REQUEST_METHOD']=='POST'){
$fs=array();
foreach ( $_FILES as $name=>$file ) {
$str=stristr($file['name'],'.'); // stristr()函数获取上传文件的后缀
// strtotime()函数定义一个Unix时间戳
$path="image/".uniqid(prefix,false).$str; // 定义上传文件的存储位置
if(move_uploaded_file($file['tmp_name'],$path)){
$fs[$name]=array('name'=>$name,'url'=>$file['name'],'type'=>$file['type'],'size'=>$file['size']);
}else{
$fs[$name]=array('name'=>$name,'url'=>'error','type'=>$file['type'],'size'=>$file['size']);
}
}
echo json_encode($fs);
}
?>
~~~
使用plus.uploader.createUpload函数上传文件时遇到一些问题,其他参数使用task.addData("name","value"),有些值传入为空可以试着加.toString()示例:task.addData("score_id",score.toString());
图片拍照功能:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link type="text/css" href="css/evaluate.css" rel="stylesheet" />
<link href="css/mui.min.css" rel="stylesheet" />
<link rel="stylesheet" type="text/css" href="css/loaders.min.css"/>
<link rel="stylesheet" type="text/css" href="css/loading.css"/>
<link rel="stylesheet" type="text/css" href="css/base.css"/>
<link rel="stylesheet" type="text/css" href="css/stylea.css"/>
<style>
#lookImg{
width: 230px;
height: 230px;
float: left;
}
#imagea{
height: 100px;
width: 100px;
}
</style>
</head>
<body>
<header class="top-header fixed-header">
<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
<h3>去评价</h3>
<a class="iconb" href="shopcar.html">
</a>
</header>
<!-- 多行文本框 -->
<!-- <div class="mui-input-row" style="margin: 70px 10px;">
<textarea rows="5" type="text" placeholder="请对本次服务做出评价吧!" ></textarea>
</div> -->
<!-- 星级评价 -->
<div id="star" data-score="1"></div>
<form id='login-form' class="mui-input-group">
<div class="contaniner fixed-cont">
<section class="assess">
<p>
<textarea rows="5" placeholder="请写下对宝贝的感受吧,对他人帮助很大哦" id="evaluate" ></textarea>
</p>
<ul>
<li>
商品评价
</li>
<li class="assess-right">
<img onclick="level(1)" src="images/detail-iocn01.png"/>
<img onclick="level(2)" src="images/detail-iocn01.png"/>
<img onclick="level(3)" src="images/detail-iocn01.png"/>
<img onclick="level(4)" src="images/detail-iocn01.png"/>
<img onclick="level(5)" src="images/detail-iocn01.png"/>
</li>
</ul>
</section>
</div>
</form>
<!-- 图片上传 -->
<div id="imagenone">
<a class="imageup 1" id="headImage"><img id="headIma" class="headimg" src='' onerror="this.src='images/scimg.png'" alt="点击上传图片" border="2" height="100" width="100">
</a>
</div>
<!-- <a class="imageup 2" id="uploadImage"><img id="headimg" class="headimg" src='' onerror="this.src='images/scimg.png'" height="100" width="100">
</a> -->
<!-- <p><button id="uploadImage" class='button'> 提交</button></p> -->
<div class="mui-content" style="background-color:#fff">
<ul id="imgaes">
</ul>
</div>
<footer class="assess-footer fixed-footer ">
<ul>
<a class="imageup 2" id="uploadImage"><input type="button" value="发表评论" id="uploadImage" class="headimg"/>
</a>
</ul>
</footer>
<script src="js/mui.min.js"></script>
<script src="js/app.js"></script>
<script src="js/mui.zoom.js"></script>
<script src="js/mui.previewimage.js"></script>
<script src="js/host.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jquery.raty.min.js"></script>
<script src="js/mui.previewimage.js"></script>
<script src="js/mui.zoom.js"></script>
<script>
// 获取商品和个人id
C1=window.location.href.split("?")[1];
C2=C1.split("=")[1];
var state = app.getState();
var user_id = state.user_id;
var evaluate = $("#evaluate").val();
var shop_id = C2;
var statrs=5;
//星级评价代码
$(".assess-footer ul li label").on('touchstart',function(){
if($(this).hasClass('assd')){
$(".assess-footer ul li label").removeClass("assd")
}else{
$(".assess-footer ul li label").addClass("assd")
};
});
function level(s)
{
var str = '';
var k = 6-s;
for(i=1;i<s+1;i++)
{
str += "<img onclick='level("+i+")' src='images/detail-iocn01.png'/>";
}
for(j=1;j<k;j++)
{
var d=j+s
str += "<img onclick='level("+d+")' src='images/detail-iocn001.png'/>";
}
$('.assess-right').html(str);
statrs = s;
// tests();
}
// function test(){
// alert(score);
// }
// 图片上传代码
//扩展API完成后执行的操作
//附件上传成功后返回的json
// $("#imagenone").hide();
var fileJson = "";
//上传附件
var fileArr = [];
var urls = [];
var imagess = [];
// 拍照获取图片
function getImage(imgsUI) {
var c = plus.camera.getCamera();
c.captureImage(function(e) {
plus.io.resolveLocalFileSystemURL(e, function(entry) {
var imgSrc = entry.toLocalURL() + "?version=" + new Date().getTime(); //拿到图片路径
setFile(imgSrc);
setHtml(imgSrc, imgsUI);
urls = [];
imagess = [];
loadImgs();
}, function(e) {
console.log("读取拍照文件错误:" + e.message);
});
}, function(s) {
console.log("erroraaa" + s.message);
}, {
filename: "_doc/camera/"
})
}
function getHeadImage(imgsUI) {
if(mui.os.plus) {
var buttonTit = [{
title: "拍照"
}, {
title: "从手机相册选择"
}];
plus.nativeUI.actionSheet({
title: "上传图片",
cancel: "取消",
buttons: buttonTit
}, function(b) { /*actionSheet 按钮点击事件*/
switch(b.index) {
case 0:
break;
case 1:
getImage(imgsUI); /*拍照*/
break;
case 2:
galleryImg(imgsUI); /*打开相册*/
break;
default:
break;
}
})
}
}
function setFile(fileSrc) {
var image = new Image();
image.src = fileSrc;
fileArr.push(image);
// alert(image);
}
function setHtml(path, imgsUI) {
// var str = '';
var str = '<li id="lookImg" class="mui-table-view-cell mui-media mui-col-xs-6">' +
'<div class="mui-content-padded">' +
'<img id="imagea" class="mui-media-object" src="' + path + '" data-preview-src="" data-preview-group="1">' + //《注意》:data-preview-group="1"这里为分组设置,如果界面中有多个div中放不同图片,那么这里要为每个组设置一个不同的值。
'<span class="mui-icon mui-icon-trash deleteBtn"></span>' + //这里是删除图片接钮
'</div>' +
'</li>';
$("#imgaes").append(str);
}
// 监听点击图片大图浏览
$(".mui-content").on('tap', '.mui-content-padded img', function() {
});
// 监听点击大图浏览图片返回
$("body").on("tap", "#__MUI_PREVIEWIMAGE", function() {
})
// 监听图片的删除点击
mui("body").on('tap', '.mui-content-padded span', function() {
$(this).closest("li").hide(800, function() {
$(this).closest("li").remove();
urls = [];
imagess = [];
loadImgs()
});
});
function loadImgs() {
// 获取图片地址列表
var images = document.querySelectorAll('.mui-content-padded img');
imagess = images;
for(var i = 0; i < images.length; i++) {
urls.push(images[i].src);
}
// alert(images.length);
var len = 4;
if(len < images.length){
$("#imagenone").hide();
}else{
$("#imagenone").show();
}
}
//图片上传
function uploadImage() {
var files = new Array();
$(".mui-content-padded").each(function(index) {
var imgurl = $(this).find('img').attr('src');
var image = new Image();
image.src = imgurl;
files.push(image);
});
if(!files) {
return;
}
// console.log("上传中...");
var wt=plus.nativeUI.showWaiting();
//获取token信息
// var appToken = localStorage.getItem("appToken");
// var tokenHeader = localStorage.getItem("tokenHeader");
//上传路径
// var mainUrls = serverip + "api/innerapi/file_upload";
var task = plus.uploader.createUpload('http://'+host+'/yungfu/evaluate.php', {
method: "POST",
}, function(t, status) { //上传完成
// mui.hideLoading();
if(status==200){
alert("评价成功:感谢您的评价!");
wt.close(); //关闭等待提示按钮
// window.close();
mui.openWindow({
url: 'orderm.html',
id:'uploadImage',
extras: {user_id:user_id}
});
} else {
alert("上传失败:" + status);
wt.close();
}
}); //将文件集合添加到上传队列中
for(var i=0;i<files.length;i++){
var f=files[i];
task.addFile(f.src,{key:i});
}
//上传时带token信息
// task.setRequestHeader(tokenHeader, appToken);
//添加其他参数
task.addData("user_id",user_id);
task.addData("shop_id",shop_id);
task.addData("evaluate",mui("#evaluate")[0].value);
var score = statrs;
task.addData("score_id",score.toString());
//开始上传
task.start();
}
// 从相册中选择图片
function galleryImg(imgsUI) {
// 从相册中选择图片
plus.gallery.pick(function(e) {
for(var i in e.files) {
var fileSrc = e.files[i];
setFile(fileSrc);
setHtml(fileSrc, imgsUI);
}
urls = [];
imagess = [];
loadImgs();
}, function(e) {
if(e.code == 8) { //没有权限
var btnArray = ["确定"];
mui.confirm('请在【设置】中打开相机及相册权限!', '相册权限未开', btnArray, function(e) {
if(e.index == 1) {
} else {
}
})
}
console.log("取消选择图片");
}, {
filter: "image",
multiple: true,
maximum: 3,
system: false,
onmaxed: function() {
onAlert('最多只能选择3张图片');
}
});
}
//点击拍照及本地相册事件
$("#headImage").on("tap", function() {
getHeadImage("#images");
})
//点击附件上传事件
$("#uploadImage").on("tap", function() {
uploadImage();
})
//大图浏览
mui.previewImage();
</script>
</body>
</html>
php接收文件代码:
~~~
<?php
include('plugin/db.php');
include('plugin/evaluate.php');
$user_id = $_POST['user_id'];
$order_id = $_POST['shop_id'];
//$order_id = 32;
//$score = $_POST['score_id'];
$score_id = $_POST['score_id'];
//
$test = evaluate::instance();
$evaluate = $_POST['evaluate'];
//
$orderm = $test->goodone($order_id);
//
$tmp = json_decode($orderm['goods'],true);
if (empty($evaluate)){
$evaluate = '此用户未填写评论。';
}
if($_SERVER['REQUEST_METHOD']=='POST'){
$fs=array();
foreach ( $_FILES as $name=>$file ) {
$str = stristr($file['name'], '.'); // stristr()函数获取上传文件的后缀
// strtotime()函数定义一个Unix时间戳
$path = "image/" . uniqid(prefix, false) . $str; // 定义上传文件的存储位置
if (move_uploaded_file($file['tmp_name'], $path)) {
// $strs = substr($path,6);
$imastr = "/yungfu/" . $path;
$tests[$name] = array($imastr);
// $tests['image'] = json_decode($imastr);
$fs[$name] = array('name' => $imastr, 'url' => $file['name'], 'type' => $file['type'], 'size' => $file['size']);
} else {
$fs[$name] = array('name' => $name, 'url' => 'error', 'type' => $file['type'], 'size' => $file['size']);
}
}
$tes = json_encode($tests);
// $test->test($tes);
foreach ($tmp as $shopkey => $shopvalue){
$shop_id = $shopvalue[0];
// print_r($shop_id);
$test->add($user_id,$shop_id,$evaluate,$tes,$score_id);
}
}
$test->upstates($order_id);
$test->delecorder($order_id);
echo json_encode($shop_id);
?>
~~~
单图上传:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
<title></title>
<link href="css/mui.min.css" rel="stylesheet" />
<link href="css/add_car.css" rel="stylesheet" type="text/css" />
<style>
.add-image{
margin: 2rem 0 0.5rem 0;
}
.imageup{ margin: 3rem 0 0 0; width:100px; height: 2rem; font-size: 1.5rem;}
.button{ width:100px; height: 50px; line-height:50px;}
</style>
</head>
<body>
<header class="mui-bar mui-bar-nav" style="padding-right: 15px;">
<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
<h1 class="mui-title">修改库存</h1>
</header>
<div class="tjiass" id="tjiadiva">
<div class="mui-input-row">
<label>银行卡姓名:</label>
<input type="text" placeholder="请输入姓名" id="car-name">
</div>
<div class="mui-input-row">
<label>银行卡类型:</label>
<input type="text" placeholder="示例:中国邮政银行" id="car-sort">
</div>
<div class="mui-input-row">
<label>银行卡号:</label>
<input type="text" placeholder="请输入18位有效银行卡号" id="car-num">
</div>
<div class="add-image">
<p><a href="javascript:;" class="imageup">点击上传微信或支付宝收款码</a> </p>
</div>
<!-- <p><button onclick="upload();" class='button'> 提交</button></p> -->
<img id="headimg" src='' height="250" width="150">
</div>
<button class="tjiabuttou" id="buttijiao">提交</button>
<script src="js/mui.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/host.js"></script>
<script src="js/app.js"></script>
<script>
var state = app.getState();
var user_id = state.user_id;
function plusReady(){
// 弹出系统选择按钮框
mui("body").on("tap",".imageup",function(){
page.imgUp();
})
}
var page=null;
page={
imgUp:function(){
var m=this;
plus.nativeUI.actionSheet({cancel:"取消",buttons:[
{title:"从相册中选择"}
]}, function(e){//1 是拍照 2 从相册中选择
switch(e.index){
case 1:appendByGallery();break;
case 2:appendByGallery();break;
}
});
}
}
// 从相册添加文件
function appendByGallery(){
plus.gallery.pick(function(path){
document.getElementById("headimg").src = path;
});
}
//服务端接口路径
var server = "http://" + host + "/songga/add_car.php";
//获取图片元素
var files = document.getElementById('headimg');
// 上传文件
var buttijiao = document.getElementById('buttijiao');
buttijiao.addEventListener('tap', function() {
// console.log(files.src);
var wt=plus.nativeUI.showWaiting();
var task=plus.uploader.createUpload(server,
{method:"POST"},
function(t,status){ //上传完成
if(status==200){
alert("上传成功:"+t.responseText);
wt.close(); //关闭等待提示按钮
}else{
alert("上传失败:"+status);
wt.close();//关闭等待提示按钮
}
}
);
//添加其他参数
task.addData("name","test");
task.addFile(files.src,{key:"dddd"});
task.start();
})
if(window.plus){
plusReady();
}else{
document.addEventListener("plusready",plusReady,false);
}
// var res = /^\+?[1-9][0-9]*$/;
//
//
// var buttijiao = document.getElementById('buttijiao');
// buttijiao.addEventListener('tap', function() {
// var name = $("#car-name").val();
// var sort = $("#car-sort").val();
// var num = $("#car-num").val();
//
// var reg = /^[0-9]+$/;
// if (num != "" && reg.test(num) && num.length == 18) {
// mui.post("http://" + host + "/songga/add_car.php", {
// name: name,
// user_id: user_id,
// sort: sort,
// num: num
//
// },
// function(data) {
//
// if (data == 'jlksdjfkjlaskj564sfa13s1a3fs5d') {
//
// alert('添加成功');
// // opener.location.reload();
// // mui.currentWebview.close();
// mui.fire(plus.webview.getWebviewById('cash'), 'refresh');
// plus.webview.getWebviewById('cash').show();
// // window.location.person.href = "updet.html";
// } else {
//
// alert('添加失败,请联系客服');
// }
//
// }, 'json'
// );
// } else {
// alert('银行卡号输入错误,请注意核对信息是否正确!');
// return false;
// }
// // alert(shop_id);
//
// });
</script>
</body>
</html>
php代码:
~~~
<?php
include('plugin/db.php');
include('plugin/stock.php');
$q = stock::instance();
$cars = array($_POST['name'],$_POST['sort'],$_POST['num']);
$car = json_encode($cars,JSON_UNESCAPED_UNICODE);
//
$file = $_FILES['dddd']['name'];
$dir = "addwechat/";
if (!is_dir($dir)){
mkdir($dir);
}
$str = stristr($file, '.'); // stristr()函数获取上传文件的后缀
$path = $dir . uniqid(addcar, false) . $str;
// 定义上传文件的存储位置
if (move_uploaded_file($_FILES['dddd']['tmp_name'], $path)) {
$imastr = "/songga/" . $path;
$tests = $imastr;
$tess = '上传成功';
} else {
$tests = '';
$tess = '上传失败';
}
$tes = json_encode($tests);
$q->user_addcar($_POST['user_id'],$car,$tes);
$a = 'jlksdjfkjlaskj564sfa13s1a3fs5d';
echo json_encode($tess);
~~~