jQuery doesn't want to reload a php function

Discussion in 'PHP' started by Mareshal, Mar 11, 2011.

  1. #1
    here is the jQuery code
    $(document).ready(function(){
    			var root = window.location.toString();	
    			$("#lwdigetup").live('click', function(){
    				var t = "<?php echo time() ?>";
    				$("#sid").val('').val("<?php echo time() ?>");
    				console.log(t);
    			});
    		});
    Code (markup):
    #sid is an input. Everytime I link on #lwidgetup, which is a link, I get exactly same value. And console is the same.

    Any ideas ?
     
    Mareshal, Mar 11, 2011 IP
  2. ThePHPMaster

    ThePHPMaster Well-Known Member

    Messages:
    737
    Likes Received:
    52
    Best Answers:
    33
    Trophy Points:
    150
    #2
    Because the time is added in PHP. Which will stay static until you refresh the page.

    Try getting the code via JS:
    
    
    $(document).ready(function(){
    			var root = window.location.toString();	
    			$("#lwdigetup").live('click', function(){
                                    var currentDate = new Date()
                                    var time = currentDate.getTime();
    				var t = time;
                                    $("#sid").val(time);
    				console.log(time);
    			});
    		});
    
    Code (markup):
     
    ThePHPMaster, Mar 11, 2011 IP
  3. artus.systems

    artus.systems Well-Known Member

    Messages:
    87
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    103
    #3
    time won't change when you click the button n amount of times, cause php has already shown you the value when the page has finished loading. Use ajax if you want time to be updated.
     
    artus.systems, Mar 11, 2011 IP
  4. Mareshal

    Mareshal Member

    Messages:
    71
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    45
    #4
    And this messed my entire day. not is obvious. I am kinda tired...need some sleep. I can't believe I posted that. I was thinking at $.get("something.php") ...
     
    Mareshal, Mar 11, 2011 IP