简体   繁体   中英

Saving Joomla front end test scores to the server

In a Joomla website I'm working on, the user does an English word knowledge test. The score on this test is calculated by some jQuery code and displayed on the test page. I want to save this score on the front end to the server as part of the user data stored there. I would like the score to be saved automatically on completion of the test. I understand that a php script will be necessary but I was wondering how a script might be triggered by jQuery. I have also looked at the SO articles "saving data from joomla frontend" and "Run php file through jquery link click". These are helpful but are there any tutorials on php scripting within the Joomla environment? I've checked the Joomla documentation but this seems to be largely oriented towards plugin development. Any help would be much appreciated Thanks in anticipation.

1) Create PHP script to store score to 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) Call PHP Script from jQuery

jQuery.get( "myPhpScript.php?task=savescore&userId=123", function( data ) {
    alert(data);
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM