我在php中有变量,我想发送到javascript中的函数,我的php就像这个
if (isset($_POST['acceptbut'])) {
**other code***
$date1 = $vals['date1'];
$date2 = $vals['date2'];
$nme = $vals['nme'];
how would I call the addMyEvent and send those variables, cant seem to find
a way anywhere to send them to the javascript function
}
我使用foreach循环从数据库中获得了这些值
您可以对$_POST或$_GET请求使用ajax。
PHP myserver.PHP:
if (isset($_POST['acceptbut'])) {
// i do something here...
// you could either echo back text or JSON
echo "Blah Blah Blah";
}
Javascript:
$.post("myserver.php", function(data){
// I do something here with the data I received
window.alert(data); // it should says Blah Blah Blah
});
PHP是服务器端,javascript是客户端,您可以做到这一点。
但是您可以使用php来形成您的javascript函数。像这样的
echo '<script type="text/javascript">' .
'function(' . $var1 . ');' .
'</script>'
;