weixin_33701564 2017-06-14 08:38 采纳率: 0%
浏览 160

将html div传递给ajax调用

So I have my server-side code which executes multiple bigquery queries and arranges the results in a table,and this server-side code is called by an ajax call from the client. I want to be able to send the table/div from my server-side code to client-side and have it render there. Is that possible??

I don't want to be able to create the tables on the client by first getting the JSON results through the call, since I will not know which query will run first and all the results are different. (multiple ajax calls are also out of the question for each query)

Server code (app.js)

 function printResult(rows, queryNumber) {
    console.log('Query No. '+queryNumber+' Results:____');
    var keys = [];
    if (queryNumber == 1) {
        var table = document.createElement('table');

        var td = [];
        var tr = document.createElement('tr');
        for (var i = 0; i < rows[0].length; i++) {
            var tn1 = document.createTextNode(rows[i].Content_title);
            var tn2 = document.createTextNode(rows[i].Audience_Size);

            td[i] = document.createElement('td');
            td[i].appendChild(tn1);
            td[i + 1] = document.createElement('td').appendChild(tn2);

            tr.appendChild(td[i]);
            tr.appendChild(td[i + 1]);
            table.appendChild(tr);
            res.send(table);
        }
    }
}

Ajax call

$.ajax({
    url: 'http://localhost:3000/example',
    type: 'POST',
    data: {showname: show, counter: uniquesOverallShowsCounter},
    dataType: 'text',
    contentType: 'application/x-www-form-urlencoded',
    success: function (data) {




        document.getElementById('outputTables').appendChild(data);


    },
    error: function() {
        console.log("error");
    }
});
  • 写回答

2条回答 默认 最新

  • 喵-见缝插针 2017-06-14 08:43
    关注

    So can you simply increase one more parameter in your response json based on the query which is hit for example "queryProcessed"?

    And add that additional check on client side and render the mark up based on that "queryProcessed"

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。