我想实现的是下图这个功能
目前树结果已经用PHP生成完成(listhou.php),怎么才能点这个树的A标签不跳转页面传参到另一个PHP页面(listhou2.php)并取回结果呢?
HTML部分代码
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>测试</title><link rel="stylesheet" type="text/css" href="style/index.css" /><script type="text/javascript" src="js/jquery-1.11.3.min.js"></script><script type="text/javascript">$(function(){ $(".listshow ul").load("listhou.php");});</script></head><body><div class="listshow" ><ul></ul><a href="222">123</a><a href="333">321</a></div><div class="list2"> </div></body></html>
listhou.php代码
<?phpheader("Content-Type:text/html;Charset=utf-8");$host='localhost';$user='root';$password='63698000xw';$database='test';$conn=mysqli_connect($host, $user, $password, $database) or die('DataBase connected error<br/>'.mysqli_connect_error($conn));$query="SELECT * FROM company";$result=mysqli_query($conn, $query); while ($row=mysqli_fetch_assoc($result)) { echo '<li>'; echo '<h5 id="row-c-name">'.$row['c_name'].'</h5>'; echo '<ul>'; $query1="SELECT * FROM department"; $result1=mysqli_query($conn, $query1); while ($row1=mysqli_fetch_assoc($result1)) { if ($row['id']==$row1['d_id']) { echo '<li><a class="geta" href="listhou2.php?userid='.$row1['id'].'">'.$row1['d_name'].'</a></li>'; } } mysqli_free_result($result1); echo '</ul>'; echo '</li>'; } mysqli_free_result($result);?>
listhou2.php代码
<?php header("Content-Type:text/html;Charset=utf-8");$host='localhost';$user='root';$password='63698000xw';$database='test';$conn=mysqli_connect($host, $user, $password, $database) or die('DataBase connected error<br/>'.mysqli_connect_error($conn)); if (isset($_GET['userid'])) { $row1id=$_GET['userid']; // echo "$row1id"; $query2="SELECT * FROM user WHERE u_id=$row1id"; $result2=mysqli_query($conn,$query2); // echo "我取得ID了"; if (mysqli_num_rows($result2)) { echo '<table border="1">'; echo "<tr><th>姓名</th><th>电话</th></tr>"; while ($row2=mysqli_fetch_assoc($result2)) { echo "<tr><td>{$row2['username']}</td><td>{$row2['tphone']}</td></tr>"; } }else{ echo "<tr><td>没有查到相关记录</td></tr>"; } $num=mysqli_num_rows($result2); echo '<tr><th colspan="2">共取出'.$num.'条数据</th></tr>'; echo '</table>'; mysqli_free_result($result2); }else{ echo "没有获取ID"; } mysqli_close($conn); ?>
回复讨论(解决方案)
是放到
$($(".listshow a").click(function() { $("list2").load($(this).attr("href")); return false;});
1、加上 点击事件 $($(".listshow a").click(function() {
2、在1的处理方法里用ajax调用
3、在listhou2.php页面里接收值,并处理,(可以返回值,也可以没有)
例 :
$.ajax({ type:'get', async : false, url: "{:U('paygoodsAjax')}", data:"ord_id="+ord_id, success: function(msg){ flag= true; //alert(msg) if(msg==1004){ flag= false; $("#jian").html("商品已下架!") $("#jian").css("display",'block'); function times(){ $("#jian").css("display",'none'); clearInterval(timer); } timer=setInterval(times,2500); } else if(msg==1003){ flag= false; $("#jian").html("商品库存不够了") $("#jian").css("display",'block'); function times(){ $("#jian").css("display",'none'); clearInterval(timer); } timer=setInterval(times,2500); }else if(msg==1002){ flag= false; $("#jian").html("订单存在过期促销商品!") $("#jian").css("display",'block'); function times(){ $("#jian").css("display",'none'); clearInterval(timer); } timer=setInterval(times,3000); } //location.reload(); } }); return flag;
后端处理
//ajax 商品支付前判断 public function paygoodsAjax(){ $ord_id=I("get.ord_id"); //echo $ord_id; $ordershopids=M("ordershop")->where("order_id = '$ord_id'")->getFields("shop_id"); //var_dump($ordershopids); //判断商品是否下架或者库存为0 if($ordershopids){ foreach($ordershopids as $id){ $goodsinfo=M("goodsshop")->where("id = '$id'")->find(); //var_dump(M("goodsshop")->getLastSql()); if($goodsinfo){ if($goodsinfo['is_up']!=1){ echo "1004";exit(); } if($goodsinfo['stock']<=0){ echo "1003";exit(); } }else{ echo "1004";exit(); } } }
是放到
$($(".listshow a").click(function() { $("list2").load($(this).attr("href")); return false;});
把这个代码加到页面后直接就一片空白了啊,是这样加吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>测试</title><link rel="stylesheet" type="text/css" href="style/index.css" /><script type="text/javascript" src="js/jquery-1.11.3.min.js"></script><script type="text/javascript"> $(function(){ $(".listshow ul").load("listhou.php");});</script></head><body><div class="listshow" ><ul></ul></div><div class="list2"> </div></body></html>
$(".listshow a").click(function() {
$("list2").load($(this).attr("href"));
return false;
});
列表在 listhou.php 产生,所以要写在
$(".listshow ul").load("listhou.php"); 的回调里
即
$(".listshow ul").load("listhou.php", {}, function() {
$(".listshow a").click(function() {
$("list2").load($(this).attr("href"));
return false;
});
});
$(".listshow a").click(function() {
$("list2").load($(this).attr("href"));
return false;
});
列表在 listhou.php 产生,所以要写在
$(".listshow ul").load("listhou.php"); 的回调里
即
$(".listshow ul").load("listhou.php", {}, function() {
$(".listshow a").click(function() {
$("list2").load($(this).attr("href"));
return false;
});
});
麻烦您再给看看还是不传参数
'.$row1['d_name'].'
又要是这样的超链
userid 传不过去?
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title> <script type="text/javascript" src="jquery.min.js"></script> <script> $(function(){ $('.listshow').load('list.php', function(){ $('.listshow a').on('click', function(){ $('.list2').load($(this).attr('href')); return false; }); }); }) </script></head><body><div class="listshow"></div><div class="list2"></div></body></html>
<?php// list.phpecho '<a href="2.php?param=1">测个试</a>';
<?php// 2.phpprint_r($_REQUEST);
楼主的代码的list2前少了一个点,估计加载不出来
OK 谢谢各位 ,解决了

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

PHP日志记录对于监视和调试Web应用程序以及捕获关键事件,错误和运行时行为至关重要。它为系统性能提供了宝贵的见解,有助于识别问题并支持更快的故障排除

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

文章讨论了PHP 5.3中引入的PHP中的晚期静态结合(LSB),从而允许静态方法的运行时分辨率调用以获得更灵活的继承。 LSB的实用应用和潜在的触摸


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3汉化版
中文版,非常好用

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

禅工作室 13.0.1
功能强大的PHP集成开发环境

SublimeText3 Mac版
神级代码编辑软件(SublimeText3)

WebStorm Mac版
好用的JavaScript开发工具