Insert value in javascript by taking php-mysql

Asked

Viewed 30 times

0

Hello, I’m not programmed, but I’m doing a website where I want to place an accountant to determine what the expiration date of the website registration will be. I used the 3D Cube Countdown script, but would like the date to come straight from php-mysql to be automatic. see part of the code

jQuery(function($){ // on DOM load

//Eg #1
var mycountdown = new cubecountdown({
    containerid: 'futuredate',

Here I would like to receive the MYSQL maturity field

targetdate: 'October 17, 2017 11:26:30', 

my doubt

    size: ['10em', '6em'], // specify cube dimensions in "em" only
    unit: ['days']
})

1 answer

0

If the / script query is done on the same page you can pass the php string to javascript as follows:

var minhaVarJS = <?=$MinhaVarPHP?>

Before moving to Javascript use json_encode() in your PHP variable.

If they are done on different pages I recommend using Ajax to retrieve this information.

$.ajax(function(){
    type: "POST",
    url: "suaURL.php",
    data: 'seu-post',
    success: function(data)
        {
            minhaVar = data;
        }
});

And in your PHP page that will receive this post you do the search in the database according to the parameters passed in date: 'your-post', after the search you give a

echo json_encode($minhaVarPHP);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.