笑故挽风 2011-12-06 15:01 采纳率: 100%
浏览 22

jQuery AJAX数据到HTML

EDIT: Ok, so the solution i came up with, is basically count the characters and see the difference between the numbers. One headache i had was related with the fact that the .html() didn't showed me the
with the slash, instead,
. Annoying....

function verifica(){
    $.ajax({
    type: "GET",
    datatype: "html",
    url: 'icallverifica.php',
    data: "valor=0",
    success: function(data) {
        var verificando = $('#results').html();
        var verificandox = (verificando.length);
        var verificador = data.length;
        if(verificandox != verificador){
            $('#results').html(data);
        }
    }
    });
}

I'm creating a little script using AJAX that retrieves data from a database. The problem is that I've used setInterval and it's refreshing all the time.

I don't have a problem with too many accesses to the database, my problem is that I want the content as static as possible until there are new entries on the database:

function verifica() {
    $.ajax({
        type: "GET",
        datatype: "html",
        url: 'icallverifica.php',
        data: "valor=0",
        success: function(data) {
            var verificando = $('#results').html();
            if (verificando != "<html>"+data+"</html>") {
                $('#results').html(data);}
            }
    });
}

The function changes the #results div introducing the database information, the thing is that I don't want to change the div content unless there are any new entries.

What I did was check on the database and compare the previous content on the div, if it's the same, it will not overwrite.

BUT, i can't put data in html format...

  • 写回答

3条回答 默认 最新

  • weixin_33743880 2011-12-06 15:04
    关注

    Did you try this instead ?

    if ( verificando != data ){
        $('#results').html(data); 
    }
    

    You shouldn't need to concatenate <html> to the data while comparing it.

    评论

报告相同问题?

悬赏问题

  • ¥100 三相直流充电模块对数字电源芯片在物理上它必须具备哪些功能和性能?
  • ¥30 数字电源对DSP芯片的具体要求
  • ¥20 antv g6 折线边如何变为钝角
  • ¥30 如何在Matlab或Python中 设置饼图的高度
  • ¥15 nginx中的CORS策略应该如何配置
  • ¥30 信号与系统实验:采样定理分析
  • ¥100 我想找人帮我写Python 的股票分析代码,有意请加mathtao
  • ¥20 Vite 打包的 Vue3 组件库,图标无法显示
  • ¥15 php 同步电商平台多个店铺增量订单和订单状态
  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别