0
我想从我的PHP输出调用JavaScript函数。从PHP输出调用JavaScript函数
问题是函数不会触发。
这里是我的代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="build_workout_functions.js" charset="UTF-8"></script>
</head>
<?php
if (isset($_GET[id])) {
echo '<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="build_workout_functions.js" charset="UTF-8">
getUserProgram('.$_GET[id].');
</script>';
}
?>
<body id="login-bg">
<div class="workout_table">
<select name="days">
<option value="A">A</option>
<option value="B">B</option>
<option value="C">C</option>
<option value="D">D</option>
<option value="E">E</option>
<option value="F">F</option>
</select>
<select name="muscles" onchange="getExercies()">
<option value="legs">legs</option>
<option value="back">back</option>
</select>
<select name="exericse"><select>
</div>
</body>
</html>
的JavaScript代码:
function getUserProgram (userId) {
alert(userId);
$.ajax({
type: "POST",
url: "get_user_program.php",
data: {id: userId}
})
.done(function(msg) {
alert("Data Saved: " + msg);
});
}
你不应该混了''
只要写为HTML格式,如果
if
条件得到满足,那么你的脚本将被写入,因此执行,否则不。注意:我假设你写了前两行
<script>
作为试验,你也打电话给getUserProgram()
作为试验。我也是在函数调用呼应
$_GET[id]
我离开$_GET[id]
,因为它是,它可以是错误的方式。来源
2014-03-03 14:21:11 alalp