weixin_33744854 2014-03-20 02:24 采纳率: 0%
浏览 65

Ajax请求“重叠”

I'm using AJAX with JQuery to pull data from a MySQL database using basically the following:

function getCard(card, lineNr, linedisplay, type){

var textToWrite;    
var d = 'card='+card;


$.ajax({
        type: "POST",
        url: "getcard.php",
        data: d,
        success: function(theXML){

            cardname = $(theXML).find('card_name').text();
            pastline = $(theXML).find('past').text();
            presentline = $(theXML).find('present').text(); 
            futureline = $(theXML).find('future').text();   
            ...

        if(type=="past") textToWrite = pastline;
        else if (type=="present") textToWrite = presentline;
        else textToWrite = futureline;
        ...


        $("#"+lineNr).html(textToWrite); 
        $("#"+linedisplay).html(textToWrite);
        $('.fancybox').prop('title', cardname);
        }   

}); 
};      

This is used to call data from a MySQL table using getcard.php (not sure if you need to see that - basically it puts the data from a table row into XML,

<card_name>{$row['card_name']}</card_name>
<past>{$row['past']}</past>
<present>{$row['present']}</present>
<future>{$row['future']}</future>, 

etc).

As a card link is clicked on, a fancybox popup comes up with the card data (pastline, etc) and the cardname as the fancybox title.

All of this works fine except for one thing. The cardname value doesn't refresh at the same rate as the rest of the data. That is, the title of the second card I click on is the same as the first card I click on - but the rest of the new data (pastline, presentline etc), which is displayed in a div, comes in fine, but the cardname won't refresh until I madly click on the fancybox a few times.

Thanks, I'm guessing my way through everything.

Is there any way to make AJAX make sure it has the most recent data and stop this from overlapping?

  • 写回答

1条回答 默认 最新

  • weixin_33690963 2014-04-18 20:22
    关注

    It seems that your card title is a fancybox .prop, whereas the card text is html inserted into the DOM by the function. Without being able to test your code, it might be that you are only binding the property with the fancybox .prop call, and fancybox needs to be fired by an event? Maybe attach it with jquery's on(), or perhaps there's something in fancybox (I'm not really familiar with it)?

    评论

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助