Send select value to PHP via Ajax

时间:2016-04-04 17:56:57

标签: javascript php jquery ajax

Have some problem sending select value to PHP via Ajax.

PHP:

<div class="kalb">
<?php
 if(isset($_POST['produktas'])) {

 $produktas = $_POST['produktas'];
 $infos = CalSkaiciuokle::where("id", $produktas);

 foreach ($infos as $info) {
      echo "<td><input type='text' name='ert' value=" $info->ert . " disabled></td>";
      echo "<td><input type='text' name='ert2' value=" . $info->ert2 . " disabled></td>";
      echo "<td><input type='text' name='ert3' value=" . $info->ert3. " disabled></td>";
      echo "<td><input type='text' name='ert4' value=" . $info->ert4. " disabled></td>";
 }
}  
</div>

jQuery:

   $('.subcategory').change(function(){
        var selected_item = $(this).val();
        console.log(selected_item);   

        $.ajax({
             type: 'post',
             url: 'ert.php',
             data: {
               produktas:selected_item
             },
             success: function (data) {
               // alert(data);
               document.getElementById("kalb").innerHTML=data;  
             }
        });
    });

When I select from select option and look to console it return value, but then I send via ajax it return a big HTML file and it destroys html structure.

0 个答案:

没有答案