Is it possible to load a page only once using AJAX?

I have an AJAX call to load a function after the page loads, the function opens the lightbox in the form of a frame with some data. The problem is that if I click the close button (lightboxes), the page loads again and again, loading the frame, so use never reaches the page under the frame layer since loading the frame in an infinite loop. Ajax repeats the function call, I think, but I would like to load the frame once, and when the user presses the X (close) button, he can return to the original page.

$(document).ready(function(){
var city = $('#citycode').html();

$.ajax({
//when page is loaded, fire the following function
success: function(){
//the function to be fired located in the page in seperate file
openX(city + //some other parameters);
}});


});

Any tips?

+3
source share
3 answers

true , , false , . :

<script type="text/javascript">

var loaded = false;

$(document).ready(function(){
var city = $('#citycode').html();

$.ajax({
//when page is loaded, fire the following function
success: function(){
if (loaded === false)
{
  //the function to be fired located in the page in seperate file
  openX(city + //some other parameters);
  loaded = true;
}
}});


});
</script>
+4

"" jQuery . true ajax, ; :

$.ajax({
  cache: false;
  success: function(...){...},
  ...
});
+1

- , ...:)

, - , ( URL- ) ?

, , preventDefault().

, , :

$('div.lightbox').live('click', function (event) {
  event.preventDefault();
});

live() .

+1
source

Source: https://habr.com/ru/post/1743693/


All Articles