我有一个没有 LMS 的 Captivate 培训,但我想从培训中发送数据。我已经编写了 javascript 来建立变量并发布到 php 页面,但我无法通过 post 获取请求。想法??
Javascript:
var currentTime = new Date();
var month = currentTime.getMonth() + 1;
var day = currentTime.getDate();
var year = currentTime.getFullYear();
var myMovie = CaptivateController("Captivate");
//Retrieves the author's name, if available
var cpInfoCourseName = myMovie.query("cpInfoCourseName");
var currentDate = year + "-" + month + "/" + day;
var cpQuizInfoPassFail = myMovie.query("cpQuizInfoPassFail"); //1 = pass; 0 = fail
var cpQuizInfoPointsscored = myMovie.query("cpQuizInfoPointsscored");
var cpQuizInfoQuizPassPercent = myMovie.query("cpQuizInfoQuizPassPercent");
var cpQuizInfoTotalCorrectAnswers = myMovie.query("cpQuizInfoTotalCorrectAnswers");
var jsonData = "{'cpInfoCourseName': cpInfoCourseName, 'currentDate': currentDate, 'cpQuizInfoPassFail': cpQuizInfoPassFail, 'cpQuizInfoPointsscored': cpQuizInfoPointsscored,'cpQuizInfoTotalCorrectAnswers':cpQuizInfoTotalCorrectAnswers}";
$.ajax({
type: "POST",
url: "../../trainingReporting.php",
dataType:"application/json",
data: jsonData,
success: function() {
//alert("Your training results were saved and sent to your regional office.");
//location.href = 'http://www.occ-connect.org/seconnect/occTrainings.php';
},
error: function() {
alert("Your data was not submitted");
}
});
PHP:
if(isset($_POST['data'])){
$jsonData = $_POST['data'];
//get region, email and ministry position of user
$userInfo = mysql_query("SELECT profilevalue_8,profilevalue_9 FROM se_profilevalues WHERE profilevalue_user_id = '".$user->user_info['user_id']."'");
while($r = mysql_fetch_array($userInfo))
{
$region = $r['profilevalue_9'];
$ministry_position = $r['profilevalue_8'];
}
$user_id = $user->user_info['user_id'];
$user_email = $user->user_info['user_email'];
mysql_query("INSERT INTO trainingReporting (json,user_email,user_id,region,ministry_position) VALUES ('$jsonData','$user_email','$user_id','$region','$ministry_position')") or die('INSERT FAILED: '. mysql_error());
echo "success!";
} else {
echo "error";
}