关于变量与循环语句的问题
各位大牛,消息想问个关于AJAX与PHP的问题,现在碰到这样的一个情况
我希望前端页面在点击某标签的时候,在下方可以显示我关于上方点击的标签进行关联的资料,代码如下
index.php
<html><br /> <head><br /> <script src="clienthint.js"></script> <br /> </head><br /> <br /> <body><br /> <br /> <form> <br /> First Name:<br /> <br /> <br /> <?php<br /> <br /> echo "<a>";<br /> echo "<i class=\"dapei_partleft\"></i>";<br /> echo "<span class=\"dapei_partmiddle\" title='teswt' name='test' onclick=\"showHint(1)\">test</span>";<br /> echo "<i class=\"dapei_partright\"></i>";<br /> echo " </a>";<br /> echo "<a>";<br /> echo "<i class=\"dapei_partleft\"></i>";<br /> echo "<span class=\"dapei_partmiddle\" title='teswt1' name='test1' onclick=\"showHint(2)\">test</span>";<br /> echo "<i class=\"dapei_partright\"></i>";<br /> echo " </a>";<br /> ?><br /> </form><br /> <br /> <p>Suggestions: <span id="txtHint"></span></p><br /> <br /> </body><br /> </html>
js clienthint代码
var xmlHttp<br /> <br /> function showHint(str)<br /> {<br /> if (str.length==0)<br /> { <br /> document.getElementById("txtHint").innerHTML=""<br /> return<br /> }<br /> xmlHttp=GetXmlHttpObject()<br /> if (xmlHttp==null)<br /> {<br /> alert ("Browser does not support HTTP Request")<br /> return<br /> } <br /> var url="gethint.php"<br /> url=url+"?q="+str<br /> url=url+"&sid="+Math.random()<br /> xmlHttp.onreadystatechange=stateChanged <br /> xmlHttp.open("GET",url,true)<br /> xmlHttp.send(null)<br /> } <br /> <br /> function stateChanged() <br /> { <br /> if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")<br /> { <br /> document.getElementById("txtHint").innerHTML=xmlHttp.responseText <br /> <br /> } <br /> }<br /> <br /> function GetXmlHttpObject()<br /> {<br /> var xmlHttp=null;<br /> try<br /> {<br /> // Firefox, Opera 8.0+, Safari<br /> xmlHttp=new XMLHttpRequest();<br /> }<br /> catch (e)<br /> {<br /> // Internet Explorer<br /> try<br /> {<br /> xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");<br /> }<br /> catch (e)<br /> {<br /> xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");<br /> }<br /> }<br /> return xmlHttp;<br /> }
处理页面代码gethint.php
<?php<br /> $q=$_GET["q"];<br /> <br /> //$select ="select * from test where cid='$q'";<br /> <br /> $hint="for($i=0;$i<2;$i++){......}";<br /> <br /> //Set output to "no suggestion" if no hint were found<br /> //or to the correct values<br /> if ($hint == "")<br /> {<br /> $response="no suggestion";<br /> }<br /> else<br /> {<br /> $response=$hint;<br /> }<br /> <br /> //output the response<br /> echo $response;<br /> ?>
因为在处理页面$hint 是需要传到前端页面的,所以我希望在处理页面将循环内容都做好之后传递,但是我这样写:$hint="for($i=0;$i 所以拜托大家有没有什么好的办法解决一下
在线等,谢谢各位了!

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa

TooptimizePHPapplicationsforperformance,usecaching,databaseoptimization,opcodecaching,andserverconfiguration.1)ImplementcachingwithAPCutoreducedatafetchtimes.2)Optimizedatabasesbyindexing,balancingreadandwriteoperations.3)EnableOPcachetoavoidrecompil

DependencyinjectioninPHPisadesignpatternthatenhancesflexibility,testability,andmaintainabilitybyprovidingexternaldependenciestoclasses.Itallowsforloosecoupling,easiertestingthroughmocking,andmodulardesign,butrequirescarefulstructuringtoavoidover-inje

PHP performance optimization can be achieved through the following steps: 1) use require_once or include_once on the top of the script to reduce the number of file loads; 2) use preprocessing statements and batch processing to reduce the number of database queries; 3) configure OPcache for opcode cache; 4) enable and configure PHP-FPM optimization process management; 5) use CDN to distribute static resources; 6) use Xdebug or Blackfire for code performance analysis; 7) select efficient data structures such as arrays; 8) write modular code for optimization execution.

OpcodecachingsignificantlyimprovesPHPperformancebycachingcompiledcode,reducingserverloadandresponsetimes.1)ItstorescompiledPHPcodeinmemory,bypassingparsingandcompiling.2)UseOPcachebysettingparametersinphp.ini,likememoryconsumptionandscriptlimits.3)Ad


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

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
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.

Notepad++7.3.1
Easy-to-use and free code editor

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