javascript - how to pass js values to PHP without page refresh or on body onload -
i have js script function return me values of js based on user hour, min, day, month, year. now, want parse these values php without page refresh. page served web services, whom call using page url using , post variables. goal simple parse these client side values server side php. js code:
var currenttime = new date(); var hours = currenttime.gethours() var minutes = currenttime.getminutes() var day = currenttime.getdate() var month = currenttime.getmonth() + 1 var year = currenttime.getfullyear() var suffix = "am"; if (hours >= 12) { suffix = "pm"; hours = hours - 12; } if (hours == 0) { hours = 12; } if (minutes < 10) { minutes = "0" + minutes }
i want this:
<?php echo $_post["hours"]; echo $_post["minutes"]; echo $_post["day"]; echo $_post["month"]; echo $_post["year"]; ?>
any possible solution or ticks or code appreciated. thank you.
you can use jquery's ajax method this:
$.ajax({ type: "post", url: "your.php", data: { "hours": hours, "minutes": minutes, "day": day, "month": month, "year": year, "suffix": suffix } }) .done(function( msg ) { console.log( "data sent server " + msg ); });
Comments
Post a Comment