jquery - Can't get PHP variable through AJAX -


i using wordpress , have page have drop down when links clicked make ajax call , pass data variable php, @ least i'm attempting lol.

when clicking on link check browser , in network tab page receive variable data object in html , ajax post's php page reason can't value.

my html

<div class="category-submenu">     <ul>         <li><a href="#" data-office="corporate">corporate</a></li>         <li><a href="#" data-office="office1">office1</a></li>         <li><a href="#" data-office="office2">office2</a></li>         <li><a href="#" data-office="office3">office3</a></li>     </ul> </div> 

my jquery

$('.category-submenu a').click(function(){     $.ajax({         type: "post",         url: "/load-team.php",         datatype: 'json',         data: {office: $(this).data('office')},         success: function(data) {             $.each( data, function(i, item) {                 alert(data[i].start);             });         }     }); }); 

my php

<?php      $office = $_get['office'];     $link = mysql_pconnect("localhost", "root", "root") or die("could not connect");      mysql_select_db("somedb") or die("could not select database");      $arr = array();     $query = mysql_query("select first_name, last_name ic_team_members office ='" . $office . "'");      while($obj = mysql_fetch_object($query)) {         $arr[] = $obj;     }      echo '{"members":'.json_encode($arr).'}';   ?> 

i'm sure there code missing or syntax might incorrect in parts can't seem find where, if place.

again want grab data object html element, pass through ajax php , return result json object, can reason think error in php.

any appreciated.

you passing post, , therefore need receive post:

$office = $_post['office']; 

otherwise, use send ajax request:

$.ajax({     type: "get",     ...  }); 

Comments

Popular posts from this blog

c# - How Configure Devart dotConnect for SQLite Code First? -

c++ - Clear the memory after returning a vector in a function -

erlang - Saving a digraph to mnesia is hindered because of its side-effects -