




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
Project2OnlineVotingSystemSchoolofSoftware,ChengduPolytechnicLecturer:MuQichunTask13AsynchronousVotingProgrammingInthepreviouscode,whenwesuccessfullyvote,wewillrefreshthehomepagetodisplaythelatestvotes.Ifthepageislongandwehavescrolledthescreenseveraltimes,whenwesuccessfullyvoteandrefreshthepage,wemaynotfindthepicture,anditisnoteasytoknowthecurrentvotes.Thisisthedrawbackofthe"synchronization"approach.Basedonthepreviousstudy,wealreadyknowthattheuseofasynchronousmodewillgreatlyenhancetheuserexperienceinwebpages.Therefore,wewillchangethevotingprocesscompletedearliertoasynchronousmode.Inordertoupdatethelatestvotesofavehicledirectlywithoutrefreshingthepage,weneedtoaddauniqueIDtoeachtextshowingthevotes.ThevalueofthisIDcanbeupdatedbytheuseof“jQuery”sothatthelatestvotesofavehiclecanbeupdated,thusrealizingasynchronousupdatingofvotes.Enterindex.phpandmodifytherelevantcodeforvehiclevotes:ProgrammingWeadda“span”tagandanIDtothevehiclevotes,andtheIDisthecombinationofthecharacter“num”andthevehicleID,sothatthevoteIDofeachvehicleisnotduplicated.Next,weentertheshowCode.phpfileandchangethevotingmodetoasynchronousvoting.Next,wemodifytheform,removethe“form”tag,changethe"Submit"buttontoanormalbutton,andthenbindtheEventofClick.ProgrammingNext,addthea“postCode”of“JavaScript”method:ProgrammingCreatethecontentof“ajaxVote.php”.ThroughtheasynchronousoperationofProject1,wealreadyknowtheproductionmethodofasynchronousoperationbackendfile.Infact,themostcriticalstepisthatwecan'tdirectlyreturnthecontent.Accordingtooursettings,weshouldreturnvariousdatain“JSON”format.InaPHPfile,allyouneedtodoistoJSONencodethearray,andthenoutputitin“JSON”format.ThefollowingisthecompletecontentoftheajaxVote.phpfile:ProgrammingProgrammingProgrammingSpecificcode<pclass="text-center">Currentnumberofvotes:<spanid="num<?phpecho$info['id'];?>"><?phpecho$info['carNum'];?></span></p>AddauniqueIDtothecurrentvote.$("#postVote").click(function(){$.ajax({url:'ajaxVote.php',data:{id:id,code:$("#code").val().trim()},dataType:'json',type:'GET',success:function(d){if(d.error==1){//Itindicatesanerrorlayer.alert(d.errMsg,{icon:2},function(index){layer.closeAll();});}else{letnum=parseInt($("#num"+id).text());$("#num"+id).text(num+1);layer.alert('Votesuccessfully',{icon:1},function(index){UsethejQuery-encapsulated“ajax”forasynchronousrequests.layer.closeAll();});}},error:function(){layer.alert(d.errMsg,{icon:3},function(index){layer.closeAll();});}})})Specificcode$a['error']=1;$a['errMsg']=‘Theremustbeanintervalofaminutebetweentwovotes.';echojson_encode($a);exit;Code-behindmodificationismainlytooutputallcontentsthroughthe“json_encode”.SummaryInthislecture,weuseanasynchronousvoting,wherethe
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 职业教育机构劳动合同7篇
- 组织学与胚胎学知到课后答案智慧树章节测试答案2025年春齐鲁医药学院
- 卫生盥洗设备批发企业数字化转型与智慧升级战略研究报告
- 童装超市企业县域市场拓展与下沉战略研究报告
- 便利店日用品零售企业ESG实践与创新战略研究报告
- 职业装企业ESG实践与创新战略研究报告
- 果肉饮料企业ESG实践与创新战略研究报告
- 理发电器设备百货企业数字化转型与智慧升级战略研究报告
- 婴幼儿辅食企业县域市场拓展与下沉战略研究报告
- 妇产科手术器械批发企业数字化转型与智慧升级战略研究报告
- 2023年江苏农牧科技职业学院单招职业适应性测试题库及答案解析
- 毛泽东诗词鉴赏分析
- 小学数学-纳税教学设计学情分析教材分析课后反思
- 量具检具清单
- YY/T 1833.2-2022人工智能医疗器械质量要求和评价第2部分:数据集通用要求
- 光催化原理(经典)课件
- 苏科版初中物理实验目录
- 如何上好一堂课(课件)
- 动车组列车乘务人员实务教材课件
- 西方文艺理论史精读文献课件
- 水利工程施工质量与安全管理知识讲稿ppt版(共243)
评论
0/150
提交评论