0

我有一个数据属性 id="Phone System" 的超链接

<a id="Phone System" class="push" href="#">test</a>

我想用 get/post 方法在 div id="drop1" 中加载一个 php 文件

<div>
<div id="drop1"></div>
<div id="drop2"></div>

</div>

这是 ajax 代码,数据 id="Phone System" 将被发送到 php 文件 dropcategory.php

$(function(){
   $('.push').click(function(){
      var id = $(this).attr('id');

       $.ajax({
          type : 'get',
           url : 'dropcategory.php', 
          data :  'cat='+id, 
       success : function(r)
           {

              $("#drop1").show();
           }
      });
   });
});

这是 php 文件 dropcategory.php

    require ('connect.php');
      $cat = $_GET['cat'];
   //some query operation

我不知道如何显示具有确定参数的 php 文件

4

2 回答 2

0

您需要使用响应数据更新 div:

$(function(){
   $('.push').click(function(e){
      e.preventDefault();
      $('#drop1').load('dropcategory.php', {cat: $(this).attr('id')});
   });
});
于 2013-08-02T03:30:12.477 回答
0
 $.ajax({
                  type : 'get',
                   url : 'dropcategory.php', 
                  data :  'cat='+id, 
               success : function(r)
                   {
                      $("#drop1").load("data.php?cat="+id);
                   }
              });

和 :

require ('connect.php');
echo $cat = $_GET['cat'];
于 2013-08-02T09:31:26.073 回答