Slider with ajax content

放肆的年华 提交于 2019-12-25 02:19:02

问题


I have a jquery slider, its like on default it is closed. So when the user try to open and ajax request is send and the data comes. My problem is each time the user closes and opens the ajax request is send. so how can i make the ajax call for the first time and if the user closes and opens the slider how to retain the data?


回答1:


You can set a variable, for example:

var alreadySent = false;

then in your ajax callback function you can change it to true (assuming you are using jQuery post):

if (!alreadySent) {
  $.post("address", params, function(data) {
    // do something
    alreadySent = true;
  });
}



回答2:


A wild guess: (I am a Javascript beginner, so this probably is a dumb idea)

You could add a class (lets call it '.clicked') to the "open link" in the ajax success function once the content has been loaded.

And than you would of course need to wrap the whole ajax code in an "if" statement to check if the link has already been clicked once and only execute the code if it hasnt been clicked and if there is no ".clicked" class applied to it yet.

I hope you get what I mean.



来源:https://stackoverflow.com/questions/7610918/slider-with-ajax-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!