How To / General

Call Joomdle web service functions using $.ajax

  • saeid
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago #1 by saeid
Hi,

I want to call Joomdle web service functions using ajax request.

I have a php file named students_no.php . this is my php code:
Code:
<?php header('Access-Control-Allow-Origin: *'); if(isset($_POST['courseid']) && is_numeric($_POST['courseid']) ){ $courseid = $_POST['courseid']; require_once 'administrator/components/com_joomdle/helpers/content.php'; $course_students_no = JoomdleHelperContent::call_method ('get_course_students_no', $courseid); echo $course_students_no; }else{ header('location:index.php'); } ?>

And my ajax request code is:
Code:
function get_course_students_no(){ var courseid = 23; $.ajax({ method:'post', url:'https://www.MyDomain.com/students_no.php', data:{courseid:courseid}, async: false, error: function(xhr, statusText, err){ alert("Error:" + xhr.status); }, success:function(result) { var myres = result; alert(myres); } }) }

The get_course_students_no function alerts: Restricted access.


How I access to Joomdle functions using ajax request?

Please Log in or Create an account to join the conversation.

  • saeid
  • Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 2 months ago - 3 years 2 months ago #2 by saeid
I set this code in the top of my php file and now it works fine.
Code:
define( '_JEXEC', 1 ); define( 'DS', DIRECTORY_SEPARATOR ); define('JPATH_BASE', dirname(FILE).DS.'..'.DS.'..' ); require_once ( JPATH_BASE .DS.'includes'.DS.'defines.php' ); require_once ( JPATH_BASE .DS.'includes'.DS.'framework.php' ); $mainframe =JFactory::getApplication('site'); $mainframe->initialise();
Last edit: 3 years 2 months ago by saeid.

Please Log in or Create an account to join the conversation.