LMS なしでホストしている Captivate トレーニングがありますが、トレーニングからのデータを送信したいと考えています。変数を設定して php ページに投稿するための JavaScript を作成しましたが、投稿経由でリクエストを取得できません。想い??
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";
}