search
HomeWeChat AppletWeChat DevelopmentPicture display problem obtained by WeChat jssdk interface

I have been studying the development of this WeChat public platform in the past few days
I am using chooseImageInterface Called to obtain the picture but it was never displayed. Some posts on Baidu did not turn out very well. Later, I finally figured out how to display it. Now I write it down. Make a backup

Some problems encountered when using WeChatJSDK
When configuring the S interfacesecuritydomain name, you need to use the first-level domain name. You cannot Use a second-level domain name, and cannot bring http or https
For example, in my testUploadimage URL is

applinzi.com


//html里的主要代码

 上传图片的测试
 图像接口
      <span>拍照或从手机相册中选图接口</span>
      <button>chooseImage</button>
    <span>图片预览</span>
    <p></p>


//js里的主要代码
<script>
    wx.ready(function () {
        //自动执行的
        wx.checkJsApi({
            jsApiList: [
                &#39;chooseImage&#39;,
            ],
            success: function (res) {
                // alert(JSON.stringify(res));
                // alert(JSON.stringify(res.checkResult.getLocation));
                // if (res.checkResult.getLocation == false) {
                    // alert(&#39;你的微信版本太低,不支持微信JS接口,请升级到最新的微信版本!&#39;);
                    // return;
                // }
            }
        });
    });
    wx.error(function (res) {
        alert(res.errMsg);
    });
 function chooseImg_Opinion() {
                wx.chooseImage({
                    success: function (res) {
                        showImgs_Opinion(res);
                    }
                });
            }
 function showImgs_Opinion(res) {
//主要是这一块的代码
     var parent = document.getElementById(&#39;photo&#39;);
     var p = document.createElement("p");
    //设置 p 属性,如 id
    p.setAttribute("id", "imgp");
     var _html="";
    for(var i in res.localIds){
           var photoSrc=res.localIds[i];
           _html=_html+&#39;
图片&#39;+i+&#39;:<img  src="/static/imghwm/default1.png"  data-src="&#39;+photoSrc+&#39;"  class="lazy"      style="max-width:90%"  style="max-width:90%" / alt="Picture display problem obtained by WeChat jssdk interface" >\n&#39;;
    }
  p.innerHTML = _html;
  parent.appendChild(p);
 </script>

The above is the detailed content of Picture display problem obtained by WeChat jssdk interface. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

DVWA

DVWA

Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

mPDF

mPDF

mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.