Fathima Atheeka
Fathima Atheeka

Reputation: 7

ajax data error

I have a error on ajax data:value see my code

   <script>
$(document).ready(function(){
$("#pros").change(function(e){
 e.preventDefault()
var value = $("#pros").val();
$.ajax({
   type: "GET",
   url: "product.php",
  dataType: "html",
   data: value,
   success: function(msg){
     $("#products").html(msg);
   }
   });
 });
      });
</script>

when i pass the value to product page then when i echo I get error Undefined index: value product.php on line 2 product.php page

$q = $_GET['value'];
echo $q;

Upvotes: 0

Views: 134

Answers (3)

Pedro del Sol
Pedro del Sol

Reputation: 2841

<script>
$(document).ready(function(){
   $("#pros").change(function(e){
     e.preventDefault()
     var value = $("#pros").val();
     $.ajax({
       type: "GET",
       url: "product.php",
       dataType: "html",
       data: {'value':value},
       success: function(msg){
          $("#products").html(msg);
       }
     });
   });
 });
</script>

Upvotes: 0

adeneo
adeneo

Reputation: 318202

$(document).ready(function () {
    $("#pros").on('change', function (e) {
        e.preventDefault()
        $.ajax({
            type: "GET",
            url : "product.php",
            dataType: "html",
            data: {value: this.value} //key / value
        }).done(function(msg) {
            $("#products").html(msg);
        });
    });
});

Upvotes: 1

moonwave99
moonwave99

Reputation: 22817

You have to send an hash:

$.ajax({
   type: "GET",
    url: "product.php",
    dataType: "html",
    data: { 'value' : $("#pros").val() },
    success: function(msg){
        $("#products").html(msg);
    }
});

Notice { 'value' : $("#pros").val() }.

Upvotes: 1

Related Questions