JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx

上传人:b****6 文档编号:3254786 上传时间:2022-11-21 格式:DOCX 页数:14 大小:45.09KB
下载 相关 举报
JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx_第1页
第1页 / 共14页
JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx_第2页
第2页 / 共14页
JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx_第3页
第3页 / 共14页
JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx_第4页
第4页 / 共14页
JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx_第5页
第5页 / 共14页
点击查看更多>>
下载资源
资源描述

JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx

《JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx》由会员分享,可在线阅读,更多相关《JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx(14页珍藏版)》请在冰豆网上搜索。

JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx

JSP中AJAX表单提交中文问题的简单解决方案GBK版本

测试通过:

Resin3.0.18,Tomcat5.0.30,5.5.20;浏览器:

IE6/Firefox2.0.

   上一篇文章JSP中AJAX的表单提交中文问题的简单解决方案 主要是针对UTF-8版本的进行处理的,鉴于中国大陆

地区大部分还是用GBK编码写JSP,因此本文就针对GBK的实践结果进行介绍.

有朋友提到当AJAX遭遇GBK的尴尬 里说当AJAX使用GBK编码后,表单提交将出现乱码.如前文所述,只要全部采用

UTF-8编码,是没有任何问题的.那么都用GBK呢?

首先要讲的是我们的文章还是一样的原则:

尽可能少的改动原来的代码来解决中文乱码问题.所以本文的示例没有用过

滤器等方法.

那么使用GBK编码到底有没有乱码问题呢?

第一个关键点就是AJAX的表单提交代码必须正确的按照HTTP规范实现,即要保持原来的GET/POST方式不变,

也要保持里面的内容和浏览器提交的内容一摸一样.以下内容摘自我编写的内部培训教材:

-----------------引用开始-----------------

首先必须要介绍一下HTTP协议和GET,POST的工作方式.

   当用户在Web浏览器地址栏中输入一个带有http:

//前缀的URL并按下Enter后,或者在Web页面中某个以http:

//开头

的超链接上单击鼠标,HTTP事务处理的第一个阶段--建立连接阶段就开始了.HTTP的默认端口是80.

   随着连接的建立,HTTP就进入了客户向服务器发送请求的阶段.客户向服务器发送的请求是一个有特定格式的ASCII消息,

其语法规则为:

<\n>

{

:

<\n>}*

<\n>

{EntityBody}

   请求消息的顶端是请求行,用于指定方法,URL和HTTP协议的版本,请求行的最后是回车换行.方法有GET,POST,HEAD,PUT,DELETE等.

在请求行之后是若干个报头(Header)行.每个报头行都是由一个报头和一个取值构成的二元对,报头和取值之间以":

"分隔;

报头行的最后是回车换行.常见的报头有Accept(指定MIME媒体类型),Accept_Charset(响应消息的编码方式),

Accept_Encoding(响应消息的字符集),User_Agent(用户的浏览器信息)等.

   在请求消息的报头行之后是一个回车换行,表明请求消息的报头部分结束.在这个\n之后是请求消息的消息实体

(EntityBody).

    Web服务器在收到客户请求并作出处理之后,要向客户发送应答消息.与请求消息一样,应答消息的语法规则为:

[]<\n>

{

:

<\n>}*

<\n>

{EntityBody}

   应答消息的第一行为状态行,其中包括了HTTP版本号,状态码和对状态码进行简短解释的消息;状态行的最后是回车换行.

状态码由3位数字组成,有5类:

1XX保留

2XX表示成功

3XX表示URL已经被移走

4XX表示客户错误

5XX表示服务器错误

例如:

415,表示不支持改媒体类型;503,表示服务器不能访问.最常见的是200,表示成功.常见的报头有:

Last_Modified

(最后修改时间),Content_Type(消息内容的MIME类型),Content_Length(内容长度)等.

   在报头行之后也是一个回车换行,用以表示应答消息的报头部分的结束,以及应答消息实体的开始.

   下面是一个应答消息的例子:

HTTP/1.0200OK

Date:

Moday,07-Apr-9721:

13:

02GMT

Server:

NCSA/1.1

MIME_Version:

1.0

Content_Type:

text/html

Last_Modified:

ThuDec509:

28:

011996

Coentent_Length:

3107

...</HTML></p><p>那么GET和POST有什么区别?</p><p>区别就是一个在URL请求里面附带了表单参数和值,一个是在HTTP请求的消息实体中.</p><p>用下面的例子可以很容易的看到同样的数据通过GET和POST来发送的区别,发送的数据是username=张三:</p><p> GET方式,浏览器键入http:</p><p>//localhost?</p><p>username=张三</p><p>GET/?</p><p>username=%E5%BC%A0%E4%B8%89HTTP/1.1</p><p>Accept:</p><p>image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,application/vnd.ms-powerpoint,application/vnd.ms-excel,application/msword,*/*</p><p>Accept-Language:</p><p>zh-cn</p><p>Accept-Encoding:</p><p>gzip,deflate</p><p>User-Agent:</p><p>Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.0;.NETCLR1.1.4322)</p><p>Host:</p><p>localhost</p><p>Connection:</p><p>Keep-Alive</p><p>POST方式:</p><p>POST/HTTP/1.1</p><p>Accept:</p><p>image/gif,image/x-xbitmap,image/jpeg,image/pjpeg,application/vnd.ms-powerpoint,application/vnd.ms-excel,application/msword,*/*</p><p>Accept-Language:</p><p>zh-cn</p><p>Content-Type:</p><p>application/x-www-form-urlencoded</p><p>Accept-Encoding:</p><p>gzip,deflate</p><p>User-Agent:</p><p>Mozilla/4.0(compatible;MSIE6.0;WindowsNT5.0;.NETCLR1.1.4322)</p><p>Host:</p><p>localhost</p><p>Content-Length:</p><p>28</p><p>Connection:</p><p>Keep-Alive</p><p>username=%E5%BC%A0%E4%B8%89</p><p>比较一下上面的两段文字,您会发现GET方式把表单内容放在前面的请求头中,而POST则把这些内容放在请求的主</p><p>体中了,同时POST中把请求的Content-Type头设置为application/x-www-form-urlencoded.而发送的正文都是一样的,</p><p>可以这样来构造一个表单提交正文:</p><p>encodeURIComponent(arg1)=encodeURIComponent(value1)&</p><p>encodeURIComponent(arg2)=encodeURIComponent(value2)&.....</p><p>注:</p><p>encodeURIComponent返回一个包含了charstring内容的新的String对象(Unicode格式),所有空格、标点、</p><p>重音符号以及其他非ASCII字符都用%xx编码代替,其中xx等于表示该字符的十六进制数。</p><p>例如,空格返回的是"%20"。</p><p>字符的值大于255的用%uxxxx格式存储。</p><p>参见JavaScript的encodeURIComponent()方法.</p><p>下面就讨论一下如何在JavaScript中执行一个GET或者POST请求.如果您用过Java,那么您可能熟悉下列的用.URLConnection类进行POST操作的代码(参考JavaTip34:</p><p>POSTingviaJava):</p><p> </p><p>URLurl;</p><p>URLConnectionurlConn;</p><p>DataOutputStreamprintout;</p><p>//URLofCGI-Binorjsp,aspscript.</p><p>url=newURL("somepage");</p><p>//URLconnectionchannel.</p><p>urlConn=url.openConnection();</p><p>//......</p><p>//Nocaching,wewanttherealthing.</p><p>urlConn.setUseCaches(false);</p><p>//Specifythecontenttype.</p><p>urlConn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");</p><p>//SendPOSToutput.</p><p>printout=newDataOutputStream(urlConn.getOutputStream());</p><p>Stringcontent="name="+URLEncoder.encode("BufordEarly")+"&email="+URLEncoder.encode("buford@known-");</p><p>printout.writeBytes(content);</p><p>printout.flush();</p><p>printout.close();</p><p>以上的代码向somepage发送了一次POST请求,数据为name=BufordEarly,email=buford@known-.</p><p>用JavaScript来执行POST/GET请求是同样的原理,下面的代码展示了分别用XMLHttpRequest对象向somepage用GET和POST两种方式发送和上例相同的数据的具体过程:</p><p>GET方式</p><p>varpostContent=</p><p>"name="+encodeURIComponent("BufordEarly")+"&email="+encodeURIComponent("buford@known-");</p><p>xmlhttp.open("GET","somepage"+"?</p><p>"+postContent,true);</p><p>xmlhttp.send(null);</p><p>POST方式</p><p>varpostContent=</p><p>"name="+encodeURIComponent("BufordEarly")+"&email="+encodeURIComponent("buford@known-");</p><p>xmlhttp.open("POST","somepage",true);</p><p>xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");</p><p>xmlhttp.send(postContent);</p><p>至此希望你已经能够理解如何用JavaScript中的XMLHttpRequest对象来执行GET/POST操作</p> </div> <div class="readmore" onclick="showmore()" style="background-color:transparent; height:auto; margin:0px 0px; padding:20px 0px 0px 0px;"><span class="btn-readmore" style="background-color:transparent;"><em style=" font-style:normal">展开</em>阅读全文<i></i></span></div> <script> function showmore() { $(".readmore").hide(); $(".detail-article").css({ "height":"auto", "overflow": "hidden" }); } $(document).ready(function() { var dh = $(".detail-article").height(); if(dh >100) { $(".detail-article").css({ "height":"100px", "overflow": "hidden" }); } else { $(".readmore").hide(); } }); </script> </div> <script> var defaultShowPage = parseInt("5"); var id = "3254786"; var total_page = "14"; var mfull = false; var mshow = false; function DownLoad() { window.location.href='https://m.bdocx.com/down/3254786.html'; } function relate() { var reltop = $('#relate').offset().top-50; $("html,body").animate({ scrollTop: reltop }, 500); } </script> <script> var pre = "https://file1.bdocx.com/fileroot1/2022-11/20/12c9b1a6-118b-46ad-bf48-a73e4ce57aff/12c9b1a6-118b-46ad-bf48-a73e4ce57aff"; var freepage = parseInt('14'); var total_c = parseInt('14'); var start = defaultShowPage; var adcount = 0; var adindex = 0; var adType_list = ";0;1;2;3;4;5;6;7;8;9;10;11;12;13;"; var end = start; function ShowSvg() { end = start + defaultShowPage; if (end > freepage) end = freepage; for (var i = start; i < end; i++) { var imgurl = pre + (i + 1) + '.gif'; var html = "<img src='" + imgurl + "' onerror=\"this.src='/images/s.gif'\" alt=\"JSP中AJAX表单提交中文问题的简单解决方案GBK版本.docx_第" + (i + 1) + "页\" width='100%'/>"; $("#page").append("<div class='page'>" + html + "</div>"); $("#page").append("<div class='pageSize'>第" + (i + 1) + "页 / 共" + total_c + "页</div>"); if(adcount > 0 && adType_list.indexOf(";"+(i+1)+";")>-1) { if(adindex > (adcount-1)) adindex = 0; $("#page").append("<div class='pagead' id='addiv"+(i + 1)+"'></div>"); document.getElementById("addiv"+(i + 1)+"").innerHTML =document.getElementById("adpre" + adindex).outerHTML; adindex += 1; } } start = end; if (start > (freepage - 1)) { if (start < total_c) { $("#pageMore").removeClass("btnmore"); $("#pageMore").html("亲,该文档总共" + total_c + "页,到这儿已超出免费预览范围,如果喜欢就下载吧!"); } else { $("#pageMore").removeClass("btnmore"); $("#pageMore").html("亲,该文档总共" + total_c + "页全部预览完了,如果喜欢就下载吧!"); } } } //$(document).ready(function () { // ShowSvg(); //}); </script> <div id="relate" class="container" style="padding:0px 0px 15px 0px; margin-top:20px; border:solid 1px #dceef8"> <div style=" font-size: 16px; background-color:#e5f0f7; margin-bottom:5px; font-weight: bold; text-indent:10px; line-height: 40px; height:40px; padding-bottom: 0px;">相关资源</div> <div id="relatelist" style="padding-left:5px;"> <ul> <li><em class="doc"/></em><a target="_parent" href="https://m.bdocx.com/doc/30873076.html" title="药厂中间站管理规程.doc">药厂中间站管理规程.doc</a> </li><li><em class="ppt"/></em><a target="_parent" href="https://m.bdocx.com/doc/30872749.html" title="02排架结构体系.ppt">02排架结构体系.ppt</a> </li><li><em class="docx"/></em><a target="_parent" href="https://m.bdocx.com/doc/30872733.html" title="双管正激电源这些问题点不容忽视!.docx">双管正激电源这些问题点不容忽视!.docx</a> </li><li><em class="pptx"/></em><a target="_parent" href="https://m.bdocx.com/doc/30872275.html" title="教师培训《备课专业化——学教评教学设计的理念与操作》荐读读书分享读书感悟PPT教学课件.pptx">教师培训《备课专业化——学教评教学设计的理念与操作》荐读读书分享读书感悟PPT教学课件.pptx</a> </li><li><em class="ppt"/></em><a target="_parent" href="https://m.bdocx.com/doc/30872152.html" title="软件研发项目经理工作职责培训.ppt">软件研发项目经理工作职责培训.ppt</a> </li><li><em class="pptx"/></em><a target="_parent" href="https://m.bdocx.com/doc/30872060.html" title="无人机航拍我的美丽校园PPT课件.pptx">无人机航拍我的美丽校园PPT课件.pptx</a> </li><li><em class="pptx"/></em><a target="_parent" href="https://m.bdocx.com/doc/30871573.html" title="建筑施工技术高职PPT完整全套教学课件.pptx">建筑施工技术高职PPT完整全套教学课件.pptx</a> </li><li><em class="pptx"/></em><a target="_parent" href="https://m.bdocx.com/doc/30871489.html" title="沙盘治疗服务流程.pptx">沙盘治疗服务流程.pptx</a> </li><li><em class="ppt"/></em><a target="_parent" href="https://m.bdocx.com/doc/30871396.html" title="数据、模型与决策-教学课件作者-李连友-第6章-方差分析.ppt">数据、模型与决策-教学课件作者-李连友-第6章-方差分析.ppt</a> </li><li><em class="pptx"/></em><a target="_parent" href="https://m.bdocx.com/doc/30871371.html" title="城市轨道交通线路与站场PPT高职完整全套教学课件.pptx">城市轨道交通线路与站场PPT高职完整全套教学课件.pptx</a> </li> </ul> </div> </div> <div class="container" style="padding:0px 0px 15px 0px; margin-top:20px; border:solid 1px #dceef8"> <div style=" font-size: 16px; background-color:#e5f0f7; margin-bottom:5px; font-weight: bold; text-indent:10px; line-height: 40px; height:40px; padding-bottom: 0px;">猜你喜欢</div> <div id="relatelist" style="padding-left:5px;"> <ul> <li><em class="doc"></em> <a href="https://m.bdocx.com/doc/1249540.html" target="_parent" title="研修观课报告.doc">研修观课报告.doc</a></li> <li><em class="docx"></em> <a href="https://m.bdocx.com/doc/1249541.html" target="_parent" title="市政道路工程试验检测项目和频率汇总表41577.docx">市政道路工程试验检测项目和频率汇总表41577.docx</a></li> <li><em class="docx"></em> <a href="https://m.bdocx.com/doc/1249542.html" target="_parent" title="一年级拼音表.docx">一年级拼音表.docx</a></li> <li><em class="docx"></em> <a href="https://m.bdocx.com/doc/1249543.html" target="_parent" title="政府行政中舆论监督的论文.docx">政府行政中舆论监督的论文.docx</a></li> <li><em class="docx"></em> <a href="https://m.bdocx.com/doc/1249544.html" target="_parent" title="施工现场易发生重大事故的部位环节的预防监控措施和预案.docx">施工现场易发生重大事故的部位环节的预防监控措施和预案.docx</a></li> <li><em class="docx"></em> <a href="https://m.bdocx.com/doc/1249545.html" target="_parent" title="安阳旅游市场调研报告.docx">安阳旅游市场调研报告.docx</a></li> <li><em class="docx"></em> <a href="https://m.bdocx.com/doc/1249546.html" target="_parent" title="语文考试反思15篇.docx">语文考试反思15篇.docx</a></li> <li><em class="docx"></em> <a href="https://m.bdocx.com/doc/1249547.html" target="_parent" title="版光学仪器及眼镜制造行业发展研究报告.docx">版光学仪器及眼镜制造行业发展研究报告.docx</a></li> <li><em class="docx"></em> <a href="https://m.bdocx.com/doc/1249548.html" target="_parent" title="云模式下基于协同库存和anp的选址分配集成决策问题研究大学论文.docx">云模式下基于协同库存和anp的选址分配集成决策问题研究大学论文.docx</a></li> </ul> </div> </div> <div style=" font-size: 16px; background-color:#e5f0f7; margin-top:20px; font-weight: bold; text-indent:10px; line-height: 40px; height:40px; padding-bottom: 0px; margin-bottom:10px;"> 相关搜索</div> <div class="widget-box pt0" style="border: none; padding:0px 5px;"> <ul class="taglist--inline multi"> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=JSP">JSP</a></li> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=AJAX">AJAX</a></li> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=%e8%a1%a8%e5%8d%95">表单</a></li> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=%e6%8f%90%e4%ba%a4">提交</a></li> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=%e4%b8%ad%e6%96%87">中文</a></li> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=%e9%97%ae%e9%a2%98">问题</a></li> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=%e7%ae%80%e5%8d%95">简单</a></li> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=%e8%a7%a3%e5%86%b3%e6%96%b9%e6%a1%88">解决方案</a></li> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=GBK">GBK</a></li> <li class="tagPopup"><a target="_parent" class="tag tagsearch" rel="nofollow" href="https://m.bdocx.com/search.html?q=%e7%89%88%e6%9c%ac">版本</a></li> </ul> </div> <br /> <div > 当前位置:<a target="_parent" href="https://m.bdocx.com/">首页</a> > <a href="https://m.bdocx.com/booklist-00020.html">高等教育</a><span> > </span><a href="https://m.bdocx.com/booklist-0002000010.html">文学</a> </div> <br /> <div class="cssnone"> <iframe title="来源" src="https://m.bdocx.com/BookRead.aspx?id=2smnJVbWF%7cY%3d&parto=4m3jbh6KmtAcrL2OiWMNy8Qh1s%2fiJNoELmcnGTKHyJsX%2fhQi4zDH1afbE%2b%2f4CkPgErsqWx1GvA%2bnIz6a8oWNncfv4vNLwKAuBD2TVeJO6QtlzvHjXq6ycotvBIh%2faX889vtdCahrfkn8KcpUxZRzm0LEf6AIsFbirkMfaJn4Ac2OY%2bgL7g%2fuFejykC%2fjJXm6VRPeeyDBiy4FVGMPUfPnGSS%2fSQf86iiw" frameborder="0" style="width: 0px; height: 0px"> </iframe> </div> <span id="LabelScript"></span> <script src="https://mstatic.bdocx.com/JS/bootstrap-collapse.js"></script> </form> <div class="siteInner_bg" style="margin-top: 40px; border: solid 0px red; margin-left: 0px; margin-right: 0px;"> <div class="siteInner"> <p style="text-align: center;">copyright@ 2008-2022 冰豆网网站版权所有</p><p style="text-align: center;">经营许可证编号:<a href="http://beian.miit.gov.cn/" target="_blank">鄂ICP备2022015515号-1</a></p><script>var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?2e77bd3f6fe91b0e21d3f22267249ee3"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script><script>(function(){ var el = document.createElement("script"); el.src = "https://lf1-cdn-tos.bytegoofy.com/goofy/ttzz/push.js?81476e42bf626128cf29544ee216a8ed7deb9487dce7ed62313212129c4244a219d1c501ebd3301f5e2290626f5b53d078c8250527fa0dfd9783a026ff3cf719"; el.id = "ttzz"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(el, s); })(window)</script> </div> </div> <div class="trnav clearfix" id="navcontent" style="display: none; background-color:#3a71b1; "> <div class="trlogoside" id="navlogo" style="display: none;"> <a href="https://m.bdocx.com/" title="冰豆网"><img src="https://www.bdocx.com/images/logo_bd.png" alt="冰豆网"></a> <div class="trnavclose" id="navclose"> <span></span> </div> </div> <div class="navcontainer"> <div class="row"> <ul class="nav navbar-nav trnavul headercontent" id="navigation" style="margin:20px 0 0px;"> <li><a target="_parent"href="https://m.bdocx.com/login.aspx">登录</a></li> <li><a target="_parent"href="https://m.bdocx.com/">首页 </a></li> <li><a target="_parent"href="https://m.bdocx.com/booklist-0.html">资源分类 </a></li> <li><a target="_parent"href="https://m.bdocx.com/UserManage/Recharge.aspx?f=0"><img src="https://m.bdocx.com/images/s.gif" alt="new" class="hottip1">升级会员 <img src="https://www.bdocx.com/FileUpload/Images/48520fea-bc98-41ae-b183-84689c7075c9.gif" alt="new" class="hottip"></a></li> <li><a target="_parent"href="https://m.bdocx.com/newslist.html">通知公告 </a></li> <li><a target="_parent"href="https://m.bdocx.com/h-0.html">帮助中心 </a></li> </ul> </div> </div> </div> <script type="text/javascript"> function stopPropagation(e) { var ev = e || window.event; if (ev.stopPropagation) { ev.stopPropagation(); } else if (window.event) { window.event.cancelBubble = true;//兼容IE } } $("#navmore").click(function (e) { $("#navcontent").show(); $("#navlogo").show(); stopPropagation(e); var navcontentwidth = $("#navcontent").width(); $('#navcontent').css({ 'right': '-' + navcontentwidth + 'px' }); $("#navcontent").show().animate({ "right": 0 }, 300); }); $(document).bind('click', function () { var navcontentwidth = $("#navcontent").width(); $("#navcontent").animate({ 'right': '-' + navcontentwidth + 'px' }, 300, function () { $("#navcontent").hide(); }); $("#navlogo").fadeOut(300); }); $("#navcontent").click(function (e) { stopPropagation(e); }); $("#navclose").click(function (e) { var navcontentwidth = $("#navcontent").width(); $("#navcontent").animate({ 'right': '-' + navcontentwidth + 'px' }, 300, function () { $("#navcontent").hide(); }); $("#navlogo").fadeOut(300); }); </script> <script> function BaseShare(title, desc, imgUrl) { var link = "https://m.bdocx.com/doc/3254786.html"; if (wx) { wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: 'wx4f717640abfd1120', // 必填,公众号的唯一标识 timestamp: '1727372823', // 必填,生成签名的时间戳 nonceStr: '4E0928DE075538C593FBDABB0C5EF2C3', // 必填,生成签名的随机串 signature: '07aa12243104f11205003caa21c80a1011a19d63',// 必填,签名,见附录1 jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline', 'updateAppMessageShareData', 'updateTimelineShareData', 'hideMenuItems'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 //openTagList: ["wx-open-launch-weapp"]//H5打开小程序 }); wx.ready(function () { //需在用户可能点击分享按钮前就先调用 wx.hideMenuItems({// 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3 menuList: ['menuItem:share:qq', 'menuItem:favorite', 'menuItem:share:QZone', 'menuItem:share:email', 'menuItem:originPage', 'menuItem:readMode', 'menuItem:delete', 'menuItem:editTag', 'menuItem:share:facebook', 'menuItem:share:weiboApp', 'menuItem:share:brand'] }); var shareData = { title: title, // 分享标题 desc: desc,//这里请特别注意是要去除html link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: imgUrl, // 分享图标 }; wx.updateAppMessageShareData(shareData);//1.4 分享到朋友 wx.updateTimelineShareData(shareData);//1.4分享到朋友圈 }); } } function BaseShare(title, desc, imgUrl, link) { if (link=="") link = "https://m.bdocx.com/doc/3254786.html"; if (wx) { wx.config({ debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。 appId: 'wx4f717640abfd1120', // 必填,公众号的唯一标识 timestamp: '1727372823', // 必填,生成签名的时间戳 nonceStr: '4E0928DE075538C593FBDABB0C5EF2C3', // 必填,生成签名的随机串 signature: '07aa12243104f11205003caa21c80a1011a19d63',// 必填,签名,见附录1 jsApiList: ['onMenuShareAppMessage', 'onMenuShareTimeline', 'updateAppMessageShareData', 'updateTimelineShareData', 'hideMenuItems'] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2 //openTagList: ["wx-open-launch-weapp"]//H5打开小程序 }); wx.ready(function () { //需在用户可能点击分享按钮前就先调用 wx.hideMenuItems({// 要隐藏的菜单项,只能隐藏“传播类”和“保护类”按钮,所有menu项见附录3 menuList: ['menuItem:share:qq', 'menuItem:favorite', 'menuItem:share:QZone', 'menuItem:share:email', 'menuItem:originPage', 'menuItem:readMode', 'menuItem:delete', 'menuItem:editTag', 'menuItem:share:facebook', 'menuItem:share:weiboApp', 'menuItem:share:brand'] }); var shareData = { title: title, // 分享标题 desc: desc,//这里请特别注意是要去除html link: link, // 分享链接,该链接域名或路径必须与当前页面对应的公众号JS安全域名一致 imgUrl: imgUrl, // 分享图标 }; wx.updateAppMessageShareData(shareData);//1.4 分享到朋友 wx.updateTimelineShareData(shareData);//1.4分享到朋友圈 }); } } </script> <script> $(document).ready(function () { var arr = $(".headercontent"); for (var i = 0; i < arr.length; i++) { (function (index) { var url = "https://m.bdocx.com/header.aspx"; $.get(url + "?t=" + (new Date()).valueOf(), function (d) { try { arr.eq(index).empty().html(d); } catch (e) { } try { arr.html(d); } catch (e) { } }); })(i); } }); </script> <script src="https://mstatic.bdocx.com/js/jquery.lazyload.js"></script> <script charset="utf-8"> $("img.lazys").lazyload({ threshold: 200, effect: "fadeIn" }); </script> </body> </html>