<code>
var
origin = location.origin;
if
(ctx !=
""
){
origin = origin + ctx +
"/"
;
}
$.ajax({
type:
"POST"
,
url: ctx +
'/weChat/getSignatureInfo'
,
data: {pageUrl:location.href.split(
'#'
)[0]},
dataType:
"json"
,
success:
function
(data){
var
configData = {
debug: false,
appId: data.appid,
timestamp: data.timestamp,
nonceStr: data.nonceStr,
signature: data.signature,
jsApiList: [
'chooseImage'
,
'uploadImage'
]
};
wx.config(configData);
wx.ready(
function
() {
var
uploadImgs =null;
wx.chooseImage({
count
: 1,
sizeType: [
'original'
,
'compressed'
],
sourceType: [
'camera'
],
success:
function
(res) {
alert(
"dep1"
);
uploadImgs = res.localIds;
alert(
"dep2"
);
var
localId = uploadImgs.pop();
alert(
"dep3"
);
wx.uploadImage({
localId:localId,
isShowProgressTips: 1,
success:
function
(res) {
alert(
"dep4"
);
var
serverId = res.serverId;
alert(
"dep5"
);
if
(serverId.indexOf(
"wxLocalResource://"
)>=0){
$(
"#errorMessage"
).text(
"图片上传失败,请重新上传!"
);
$(
'.phone_layer_box'
).show();
return
;
}
sessionStorage.setItem(
"imgSrcA"
,uploadImgs);
$(
"#img_upload_site_A"
).html(
"<img src=\'"
+localId+
"\' class='img_upload_site' />"
);
$(
"#imgAs"
).val(localId);
$(
"#imgA"
).attr(
"value"
,serverId);
}
});
}
});
});
wx.error(
function
(res){
});
}
});</code>