0

I have a div element where a file is being loaded every 10500 miliseconds;

index.php

...
<div class="loadHere"></div>
...

code that loads every few seconds.

setInterval(
function ()
{
$('.loadHere').unload().load('filetoload.php').fadeIn('slow');

}, 10500);

filetoload.php

<a href="#" class="testbtn">test</a>
<input type="hidden" value="1234" class="hiddenelement"/>

and this is what i'm trying to do but isn't working:

$(document).on('click','.testbtn',function(event)
{
      event.preventDefault();

     var xyz = $('.hiddenelement').val();

    alert(xyz);


});

2 Answers2

0

Use Callback function:

$( "#success" ).load( "/not-here.php", function( response, status, xhr ) {
  if ( status == "error" ) {
    var msg = "Sorry but there was an error: ";
    $( "#error" ).html( msg + xhr.status + " " + xhr.statusText );
  }
});

From Jquery Docs

0

Your strategy seems to work.

setInterval(
function () {
   $('.loadHere').unload().load('toload.php').fadeIn('slow');

}, 10500);


$(document).on('click','.testbtn',function(event)
{
  event.preventDefault();

 var xyz = $('.hiddenelement').val();

alert(xyz);
});

Here is the working plunker : http://plnkr.co/edit/tiLv3WMDCjoW3Ggb9bTH?p=preview.

victor
  • 1,626
  • 1
  • 14
  • 23