Ajax响应在控制台它'ok,但在php页面不'到达


Ajax response in console it's ok, but in php page doesn't arrive

我一直在为我的问题寻找答案,但我尝试的每一个解决方案都不起作用。

我有一个html select
    <select id="exampleid">
     <option>Option1</option>
     <option selected>Option2</option>
     <option>Option3</option>
    </select>
Ajax请求

    $('#exampleid').change(function(){
       var aabbcc = $(this).val().trim();
       $.post("_ws/rca.php?action=brands", {aabbcc:aabbcc}, function(response) {
       console.log('search is: ' + aabbcc + ', Response from PHP script: ' + response);
         });
})

在控制台中返回:

search is: Option2, Response from PHP script: array(1) {
  ["aabbcc"]=>
  string(27) "Option2"
}
PHP

if($action == 'brands'){ //action is relevant for link where send the ajax
var_dump($_POST['aabbcc']);
exit;
}

问题是,$_POST返回空数组。我也检查了print_r和var_dump。显然AJAX发送了正确的请求,但在PHP中没有到达。

我检查了404错误或类似的东西,但一切似乎都很好。

提前感谢。

你的主页:

<select id="exampleid">
         <option>Option1</option>
         <option>Option2</option>
         <option>Option3</option>
    </select>
<div class="result">none</div>
<script type="text/javascript">
        $('#exampleid').change(function(){  
            var aabbcc = $(this).val().trim();
            $.post("rca.php?action=brands", {aabbcc:aabbcc}, function(response) {
                console.log('Search is: ' + aabbcc + ', Response from PHP script: ' + response);
                $( ".result" ).html( response );
            });
        })
</script>

这是你的回调rca。php

if($_GET['action']=='brands') {
        echo 'PHP: '.$_POST['aabbcc'];
        return;
    }