How do you output a query from a .cfm page using jQuery AJAX in JSON format?

后端 未结 3 1841
失恋的感觉
失恋的感觉 2021-01-28 13:36

I am trying to output a query from a .cfm page using jquery with json format. Can someone tell me what I am dong wrong?

Edit: Answer here

Edit: Just posted my cf

3条回答
  •  余生分开走
    2021-01-28 14:29

    ./test.cfm:

       
       
       #SerializeJSON(getItems)#
    

    Here's some of my code that I've modified to match your example:

    My HTML:

    And my javascript, which puts the query result into the table:

        $("#runQuery").click(function () {
    
            $.ajax({
    
                type: "GET",
                url: "./test.cfm",
                dataType: "json",
                success: function (resp, textStatus, jqXHR) {
                    buildResultsTable(resp);
                },
                error: function (jqXHR, textStatus, errorThrown)
                {
                    alert(errorThrown); 
                }
            });
    
        });
    
    
        function buildResultsTable(resp)
        {
            var tmp_html = $("");
            var j = 0;
    
                $("#results").html(""); 
    
                for (var i = 0; i < resp["COLUMNS"].length; i++)
                {
                    var tmp_th = $("");   
                    tmp_th.text(resp["COLUMNS"][i]);
                    tmp_html.append(tmp_th);
                }
                $("#results").append(tmp_html);
    
                for (j = 0; j < resp["DATA"].length; j++)
                {
                    tmp_html = $("");
    
                    for (var i = 0; i < resp["DATA"][j].length; i++)
                    {
                        var tmp_td = $("");   
                        tmp_td.text(resp["DATA"][j][i]);
                        tmp_html.append(tmp_td);
                    }
                    $("#results").append(tmp_html);
                }
    
        }
    

提交回复
热议问题