0

i have a hyperlink with data property id="Phone System"

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

i want to load a php file in div id="drop1" with get/post method

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

</div>

here is the ajax code, the data id="Phone System" will be send to php file 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();
           }
      });
   });
});

and here is the php file dropcategory.php

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

i have no idea how to show php file with determined parameter

ocit
  • 125
  • 1
  • 2
  • 9
  • Add the cat parameter to your url parameter `url : 'dropcategory.php?cat='+id` – Raab Aug 02 '13 at 03:25
  • I'm not sure what your problem but try, `data : {cat:id}, ` instead of a string – Musa Aug 02 '13 at 03:25
  • i think the problem in the success function(r)? – ocit Aug 02 '13 at 03:26
  • I have no idea about what kind of job you intend to do here but I could see some problems from your code, you had invalid id(has space) http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html?answertab=active#tab-top wrong ajax data syntax – Telvin Nguyen Aug 02 '13 at 03:31
  • thank you all, it is work when i add $("#drop1").show().html(r); in success : function(r) – ocit Aug 02 '13 at 03:36
  • possible duplicate of [jQuery AJAX POST example](http://stackoverflow.com/questions/5004233/jquery-ajax-post-example) – NullPoiиteя Aug 02 '13 at 03:36

2 Answers2

0

You need to update the div with the response data:

$(function(){
   $('.push').click(function(e){
      e.preventDefault();
      $('#drop1').load('dropcategory.php', {cat: $(this).attr('id')});
   });
});
xdazz
  • 158,678
  • 38
  • 247
  • 274
  • thank you all, but it is work when i add $("#drop1").show().html(r); in success : function(r) – ocit Aug 02 '13 at 03:36
  • @ocit Also take a look at `ID Naming Rule` http://stackoverflow.com/questions/70579/what-are-valid-values-for-the-id-attribute-in-html – Konsole Aug 02 '13 at 03:50
0
 $.ajax({
                  type : 'get',
                   url : 'dropcategory.php', 
                  data :  'cat='+id, 
               success : function(r)
                   {
                      $("#drop1").load("data.php?cat="+id);
                   }
              });

and :

require ('connect.php');
echo $cat = $_GET['cat'];