我想实现的是下图这个功能
目前树结果已经用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 谢谢各位 ,解决了

What’s still popular is the ease of use, flexibility and a strong ecosystem. 1) Ease of use and simple syntax make it the first choice for beginners. 2) Closely integrated with web development, excellent interaction with HTTP requests and database. 3) The huge ecosystem provides a wealth of tools and libraries. 4) Active community and open source nature adapts them to new needs and technology trends.

PHP and Python are both high-level programming languages that are widely used in web development, data processing and automation tasks. 1.PHP is often used to build dynamic websites and content management systems, while Python is often used to build web frameworks and data science. 2.PHP uses echo to output content, Python uses print. 3. Both support object-oriented programming, but the syntax and keywords are different. 4. PHP supports weak type conversion, while Python is more stringent. 5. PHP performance optimization includes using OPcache and asynchronous programming, while Python uses cProfile and asynchronous programming.

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values and handle functions that may return null values.


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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development 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.