将 Joomla 前端测试成绩保存到服务器
Saving Joomla front end test scores to the server
在我正在处理的 Joomla 网站中,用户进行了英语单词知识测试。此测试的分数由一些 jQuery 代码计算并显示在测试页面上。我想将前端的这个分数作为存储在那里的用户数据的一部分保存到服务器。我希望在测试完成后自动保存分数。我知道 php 脚本是必需的,但我想知道 jQuery 如何触发脚本。我还查看了 SO 文章 "saving data from joomla frontend" 和 "Run php file through jquery link click"。这些很有帮助,但是是否有任何关于 php 在 Joomla 环境中编写脚本的教程?我检查了 Joomla 文档,但这似乎主要面向插件开发。任何帮助将不胜感激感谢期待。
1) 创建 PHP 脚本以将分数存储到 DB
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', '/home/snehapur/snehyog');
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
$task = JRequest::getVar('task');
if($task == 'savescore') {
$userId = JRequest::getVar('userId');
$score = JRequest::getVar('score');
// php code to save score in DB
}
?>
2) 从 jQuery
调用 PHP 脚本
jQuery.get( "myPhpScript.php?task=savescore&userId=123", function( data ) {
alert(data);
});
在我正在处理的 Joomla 网站中,用户进行了英语单词知识测试。此测试的分数由一些 jQuery 代码计算并显示在测试页面上。我想将前端的这个分数作为存储在那里的用户数据的一部分保存到服务器。我希望在测试完成后自动保存分数。我知道 php 脚本是必需的,但我想知道 jQuery 如何触发脚本。我还查看了 SO 文章 "saving data from joomla frontend" 和 "Run php file through jquery link click"。这些很有帮助,但是是否有任何关于 php 在 Joomla 环境中编写脚本的教程?我检查了 Joomla 文档,但这似乎主要面向插件开发。任何帮助将不胜感激感谢期待。
1) 创建 PHP 脚本以将分数存储到 DB
<?php
define( '_JEXEC', 1 );
define('JPATH_BASE', '/home/snehapur/snehyog');
require_once ( JPATH_BASE .'/includes/defines.php' );
require_once ( JPATH_BASE .'/includes/framework.php' );
/* Create the Application */
$mainframe =& JFactory::getApplication('site');
$task = JRequest::getVar('task');
if($task == 'savescore') {
$userId = JRequest::getVar('userId');
$score = JRequest::getVar('score');
// php code to save score in DB
}
?>
2) 从 jQuery
调用 PHP 脚本jQuery.get( "myPhpScript.php?task=savescore&userId=123", function( data ) {
alert(data);
});