user2274075
user2274075

Reputation: 117

Showing ouput generated from an ajax request into a html div

I am working on a form on which I want to show the records related to the value user selects from the combo box and show them all into a <div> so I wrote down my code but the problem is that the request is being transferred to the external file, but it is not showing the output.

Here is my code:

$("#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");  
    }
})

Upvotes: 0

Views: 63

Answers (2)

MrCode
MrCode

Reputation: 64526

In the success event, you refer to the data variable, but your response is in result not data. Change to:

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

A minor improvement would be to use an object to pass the tagid instead of concatenating. The benefit of this is that jQuery will automatically handle the URL encoding of the value.

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

Upvotes: 2

Mina
Mina

Reputation: 1516

Your callback uses result not data

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

Upvotes: 1

Related Questions