2013-10-14 51 views
0

我正在處理一個表單,我想在其上顯示與用戶從組合框中選擇的值相關的記錄,並將它們全部顯示爲<div>,因此我寫下了我的代碼,但問題是請求正在傳輸到外部文件,但它不顯示輸出。顯示從ajax請求生成的輸出到html div

這裏是我的代碼:

$("#tag_header").change(function(){ 
    if($("#tag_header>option:selected").val() !==""){ 
     $("#brand_name").removeAttr("readonly",false); 
     $("#brand_name").css("background", "white");  
     var tagid = $("#tag_header>option:selected").val() ; 
     $.get("view_product_dtl.php?tag_header="+tagid,function(result){ 
      $("#grid").html(data); 
     }); 
    }else{ 
     $("#brand_name").attr("readonly",true); 
     $("#brand_name").css("background", "#C0C0C0"); 
    } 
}) 

回答

2

在成功的情況下,你指的是data變量,但你的反應是resultdata。更改爲:

$("#grid").html(result); 

A小調的改進是使用一個對象傳遞tagid,而不是串聯的。這樣做的好處是jQuery將自動處理值的URL編碼。

$.get("view_product_dtl.php", { tag_header : tagid }, function(result){ 
    $("#grid").html(result); 
}); 
1

你的回調使用resultdata

$.get("view_product_dtl.php?tag_header="+tagid,function(result){ 
    //$("#grid").html(data); 
    $("#grid").html(result); 
});