javascript - AJAX post to PHP empty -


i have checked other questions - not duplicate. have tried of solutions find , implement.

i trying send data task.php → showcats.php

task.php:

<script type="text/javascript">      $(document).on("click", ".btncat", function () {         var filter = $(this).data("id");          alert(filter);         $.ajax({             type: 'post',             url: 'showcats.php',             data: {'filter': filter},         });         $('div.container-fluid').load('showcats.php');     });  </script> 

showcats.php:

$area = $_post['filter'];  $sql = "select aid,name,surname,street_name,house_number, area, plz,poster,visible addresses area '$area' , visible 'show' order aid desc"; $rs = mysqli_query($con,$sql); $str = '';  while ($res = mysqli_fetch_array($rs)) {     $str .= '     <div class="col-md-9">         <div class="task col-md-12 well" id='.$res['aid'].'>             <div>                 <button class="btn btn-danger btn-xs btndelete" id='.$res["poster"].' onclick="refresh()" data-id="'.$res['aid'].'">x</button>             </div>             <div>                 <span>'. $res["name"].'</span>                 <span>'. $res["surname"].'</span><br>                 <span>'. $res["street_name"].'</span>                 <span>'. $res["house_number"].'</span><br>                 <span>'. $res["plz"].'</span>                 <span>'. $res["area"].'</span>             </div>         </div>     </div>'; }  echo $str; ?> 

var_dump($_post); returns null, though can see post value under developer tools in chrome.

my get:

request url:https://example.com/showcats.php request method:get status code:200 ok remote address:xxx:443 response headers view source cache-control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 connection:keep-alive content-encoding:gzip content-type:text/html; charset=utf-8 date:fri, 15 jul 2016 18:43:56 gmt expires:thu, 19 nov 1981 08:52:00 gmt pragma:no-cache server:nginx/1.6.2 strict-transport-security:max-age=31536000 transfer-encoding:chunked request headers view source accept:text/html, */*; q=0.01 accept-encoding:gzip, deflate, sdch, br accept-language:en-us,en;q=0.8,de;q=0.6 connection:keep-alive cookie:phpsessid=vudgbb33574tfod2vu48hst830 host:example.com referer:https://example.com/tasks.php user-agent:mozilla/5.0 (macintosh; intel mac os x 10_11_5) applewebkit/537.36 (khtml, gecko) chrome/51.0.2704.103 safari/537.36 x-requested-with:xmlhttprequest 

my post:

request url:https://example.com/showcats.php request method:post status code:200 ok remote address:xxx:443 response headers view source cache-control:no-store, no-cache, must-revalidate, post-check=0, pre-check=0 connection:keep-alive content-encoding:gzip content-type:text/html; charset=utf-8 date:fri, 15 jul 2016 18:43:56 gmt expires:thu, 19 nov 1981 08:52:00 gmt pragma:no-cache server:nginx/1.6.2 strict-transport-security:max-age=31536000 transfer-encoding:chunked request headers view source accept:*/* accept-encoding:gzip, deflate, br accept-language:en-us,en;q=0.8,de;q=0.6 connection:keep-alive content-length:12 content-type:application/x-www-form-urlencoded; charset=utf-8 cookie:phpsessid=vudgbb33574tfod2vu48hst830 host:example.com origin:https://example.com referer:https://example.com/tasks.php user-agent:mozilla/5.0 (macintosh; intel mac os x 10_11_5) applewebkit/537.36 (khtml, gecko) chrome/51.0.2704.103 safari/537.36 x-requested-with:xmlhttprequest form data view source view url encoded filter:turgi 

you trying send data task.php -> showcats.php ! code using this:

$.ajax({     type: 'post',     url: 'showcats.php',     data: {'filter': filter}, }); 

the problem when : $('div.container-fluid').load('showcats.php'); get request sent server! it's normal find var_dump($_post) return null.

if want show/get response can use success event this:

$.ajax({     type: 'post',     url: 'showcats.php',     data: {'filter': filter},     //a function called if request succeeds.     success: function(data) {        $('div.container-fluid').html(data)    },    //a function called if request fails    error: function(xhr, status, error) {        alert('an error occurred:'+error);    } }); 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -