0

我在 ajax 数据上有一个错误:值见我的代码

   <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>

当我将值传递给产品页面时,当我回显时,我得到错误 Undefined index: value product.php on line 2 product.php page

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

3 回答 3

1

你必须发送一个哈希:

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

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

于 2013-02-20T16:59:19.297 回答
1
$(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);
        });
    });
});
于 2013-02-20T17:00:21.437 回答
0
<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>
于 2013-02-20T17:03:34.020 回答