Home Backend Development PHP Tutorial 关于变量与循环语句的有关问题

关于变量与循环语句的有关问题

Jun 13, 2016 pm 12:34 PM
echo gt lt nbsp

关于变量与循环语句的问题
各位大牛,消息想问个关于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>
Copy after login

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 />
}
Copy after login

处理页面代码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 />
?>
Copy after login

因为在处理页面$hint 是需要传到前端页面的,所以我希望在处理页面将循环内容都做好之后传递,但是我这样写:$hint="for($i=0;$i 所以拜托大家有没有什么好的办法解决一下
  在线等,谢谢各位了!

Statement of this Website
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 Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Solution: Your organization requires you to change your PIN Solution: Your organization requires you to change your PIN Oct 04, 2023 pm 05:45 PM

Solution: Your organization requires you to change your PIN

How to adjust window border settings on Windows 11: Change color and size How to adjust window border settings on Windows 11: Change color and size Sep 22, 2023 am 11:37 AM

How to adjust window border settings on Windows 11: Change color and size

How to change title bar color on Windows 11? How to change title bar color on Windows 11? Sep 14, 2023 pm 03:33 PM

How to change title bar color on Windows 11?

How to enable or disable taskbar thumbnail previews on Windows 11 How to enable or disable taskbar thumbnail previews on Windows 11 Sep 15, 2023 pm 03:57 PM

How to enable or disable taskbar thumbnail previews on Windows 11

OOBELANGUAGE Error Problems in Windows 11/10 Repair OOBELANGUAGE Error Problems in Windows 11/10 Repair Jul 16, 2023 pm 03:29 PM

OOBELANGUAGE Error Problems in Windows 11/10 Repair

What are the differences between Huawei GT3 Pro and GT4? What are the differences between Huawei GT3 Pro and GT4? Dec 29, 2023 pm 02:27 PM

What are the differences between Huawei GT3 Pro and GT4?

Display scaling guide on Windows 11 Display scaling guide on Windows 11 Sep 19, 2023 pm 06:45 PM

Display scaling guide on Windows 11

10 Ways to Adjust Brightness on Windows 11 10 Ways to Adjust Brightness on Windows 11 Dec 18, 2023 pm 02:21 PM

10 Ways to Adjust Brightness on Windows 11

See all articles