废话不多说上代码:
前台:
function on_post_form(){ var f = document.post_myform; var s_paramName = document.getElementById("select_paramName").value; f.action = "__APP__/index/select_infomessage-s_paramName-"+encodeURIComponent(s_paramName)+".html"; f.submit();}<input name="select_paramName" class="KeyWord" id="select_paramName" size="20" maxlength="30" type="text"><div id="searchresult" style="display: none;"></div>
$(document).ready(function(){ $('#select_paramName').keyup(function(){ //输入框的id为search,这里监听输入框的keyup事件 $.ajax({ type:"GET", //AJAX提交方式为GET提交 url:"__APP__/index/get_search_showdiv", //处理页的URL地址 data:"s_Name="+encodeURIComponent($('#select_paramName').val()), //要传递的参数 success:function(data){ //成功后执行的方法 if(data != ""){ var ss; ss = data.split("@"); //分割返回的字符串 var layer; layer = "<table>"; //创建一个table for(var i=0;i<ss.length-1;i++){ layer += "<tr><td class='line'>"+ss[i]+"</td></tr>"; } layer += "</table>"; $('#searchresult').empty(); //先清空#searchresult下的所有子元素 $('#searchresult').append(layer);//将刚才创建的table插入到#searchresult内 $("#searchresult").css("display", ""); $('.line').hover(function(){ //监听提示框的鼠标悬停事件 $(this).addClass("hover"); },function(){ $(this).removeClass("hover"); }); $('.line').click(function(){ //监听提示框的鼠标单击事件 $('#select_paramName').val($(this).text()); $("#searchresult").css("display", "none"); ChangeCoords(); }); }else{ $('#searchresult').empty(); } } }); });});
后台:
public function get_search_showdiv() { //urlencode urldecode 文本框自动提示 $keyword = urldecode($_GET['s_Name']); $condition = "f_hotname like '%".$keyword."%'"; $info=$this->model->table('forest')->field('f_hotname')->where($condition)->order('f_id desc')->limit(5)->select(); if($keyword !=""){ foreach($info as $vo) { echo $vo['f_hotname'].'@'; } }else{ echo ""; } }
问题症状:比如输入“百度”
在div #searchresult 里显示:
百度杀毒
百度卫士
百度影音
如果选择第一项百度杀毒,火狐浏览器这样显示:
http://192.168.1.101/index/select_infomessage-s_paramName-%EF%BB%BF%百度杀毒.html
什么也没有。。。
如果选择第二项百度卫士,火狐浏览器这样显示:
http://192.168.1.101/index/select_infomessage-s_paramName-百度卫士.html
正常搜索,可以搜索到信息。其它项也是正常,唯独第一项就不正常。
度娘说是bom头,我所有页面都是去bom头的,编码也是utf8,尝试了很多也解决不了问题。
为什么会在第一项时候会加入%EF%BB%BF%,,,,, 在其它项都可以正常显示的。
回复讨论(解决方案)
%EF%BB%BF 不就是 BOM 头的 url 编码吗?
因为只有一个,所以你程序加载的文件中,只有一个有 BOM 头
public function get_search_showdiv()
这个函数所在php脚本文件有BOM
%EF%BB%BF 不就是 BOM 头的 url 编码吗?
因为只有一个,所以你程序加载的文件中,只有一个有 BOM 头
不好意思,这几天出差,刚刚回来,什么意思,没看明白。
utf-8 文件的 BOM 头的十六进制表示是 EFBBBF
url 编码后是 %EF%BB%BF
ajax 请求的 url 为 __APP__/index/get_search_showdiv
显然这是在使用框架
框架在处理一个请求时,至少会加载 3 个文件
所以任何一个被加载的文件有 BOM 头,返回的内容就会有 BOM 头
连接变成 ....%EF%BB%BF百度杀毒.html
而不是 ....%EF%BB%BF%EF%BB%BF百度杀毒.html
就表示只有一个文件有 BOM 头
ajax 收到的是形如 xxx@xxx@xxx@ 的串
BOM 当然是附加在内容前面的: BOMxxx@xxx@xxx@
拆分成数组后,自然是只有第一项有 BOM 啦
那怎么解决这个问题呢

TomakePHPapplicationsfaster,followthesesteps:1)UseOpcodeCachinglikeOPcachetostoreprecompiledscriptbytecode.2)MinimizeDatabaseQueriesbyusingquerycachingandefficientindexing.3)LeveragePHP7 Featuresforbettercodeefficiency.4)ImplementCachingStrategiessuc

ToimprovePHPapplicationspeed,followthesesteps:1)EnableopcodecachingwithAPCutoreducescriptexecutiontime.2)ImplementdatabasequerycachingusingPDOtominimizedatabasehits.3)UseHTTP/2tomultiplexrequestsandreduceconnectionoverhead.4)Limitsessionusagebyclosin

Dependency injection (DI) significantly improves the testability of PHP code by explicitly transitive dependencies. 1) DI decoupling classes and specific implementations make testing and maintenance more flexible. 2) Among the three types, the constructor injects explicit expression dependencies to keep the state consistent. 3) Use DI containers to manage complex dependencies to improve code quality and development efficiency.

DatabasequeryoptimizationinPHPinvolvesseveralstrategiestoenhanceperformance.1)Selectonlynecessarycolumnstoreducedatatransfer.2)Useindexingtospeedupdataretrieval.3)Implementquerycachingtostoreresultsoffrequentqueries.4)Utilizepreparedstatementsforeffi

PHPisusedforsendingemailsduetoitsbuilt-inmail()functionandsupportivelibrarieslikePHPMailerandSwiftMailer.1)Usethemail()functionforbasicemails,butithaslimitations.2)EmployPHPMailerforadvancedfeatureslikeHTMLemailsandattachments.3)Improvedeliverability

PHP performance bottlenecks can be solved through the following steps: 1) Use Xdebug or Blackfire for performance analysis to find out the problem; 2) Optimize database queries and use caches, such as APCu; 3) Use efficient functions such as array_filter to optimize array operations; 4) Configure OPcache for bytecode cache; 5) Optimize the front-end, such as reducing HTTP requests and optimizing pictures; 6) Continuously monitor and optimize performance. Through these methods, the performance of PHP applications can be significantly improved.

DependencyInjection(DI)inPHPisadesignpatternthatmanagesandreducesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itallowspassingdependencieslikedatabaseconnectionstoclassesasparameters,facilitatingeasiertestingandscalability.

CachingimprovesPHPperformancebystoringresultsofcomputationsorqueriesforquickretrieval,reducingserverloadandenhancingresponsetimes.Effectivestrategiesinclude:1)Opcodecaching,whichstorescompiledPHPscriptsinmemorytoskipcompilation;2)DatacachingusingMemc


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
