javascript - $_POST value from form select not working -


on button click, using ajax request post select data php page. reason cannot php if statements evaluate true. defaulting else condition of business_unit_brand = 3. tried echoing , print_r $brand_bu variable see holds no luck.

form:

    <select id="brand_bu" name="selected" class="form-control">      <option value="1">1</option>     <option value="2">2</option>     <option value="3">3</option>     <option value="4">4</option>     <option value="5">5</option>   </select>        <span class="input-group-btn">         <button class="btn btn-success" id="submitbu" type="button" tabindex="-1" action=""><span class="glyphicon glyphicon-retweet" aria-hidden="true"></span></button>       </span> 

jquery ajax

$("#submitbu").click(function(event) { console.log("chose bu: " + $("#brand_bu").val());  $.ajax({      url: "table.php",     type: "post",     datatype:'json',     data: json.stringify({'bu': $('#brand_bu').val()}),     success: function(data){ console.dir(data); refreshtable(); },     error: function(){alert("something went wrong, please close page , re-open.")} }); }); 

php:

    $brand_bu = $_post['bu'];  if ($brand_bu == "1"){     $business_unit_brand = "1"; } else if ($brand_bu == "2"){     $business_unit_brand = "2"; } else if ($brand_bu == "3"){     $business_unit_brand = "3"; } else if ($brand_bu == "4"){     $business_unit_brand = "4"; } else if ($brand_bu == "5"){     $business_unit_brand = "5"; } else {     $business_unit_brand = "3"; } 

php expects post data in application/x-www-form-urlencoded format, not json. $.ajax automatically encode object properly. change to:

data: { bu: $("#brand_by").val() }, 

Comments