Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8312243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:06:03+00:00 2026-06-08T20:06:03+00:00

Still having problems figuring out how to use Ajax and the Joomla framework together.

  • 0

Still having problems figuring out how to use Ajax and the Joomla framework together. I’ve created a Joomla component which I can access with:

index.php?option=com_mycomponent

I’m using Jquery with Ajax in components/com_mycomponent/views/mycomponent/tmpl/default.php:

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
<html>
<head>
  <title>Ajax with jQuery Example</title>

<script language="javascript" type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/JavaScript">
  $(document).ready(function(){
    $("#generate").click(function(){
  $("#quote p").load("components/com_mycomponent/views/mycomponent/tmpl/script.php");

    });
  });
  </script>
</head>
<body>
  <div id="wrapper">
    <div id="quote"><p> </p></div>
    <input type="submit" id="generate" value="Generate!">
  </div>
</body>
</html>

Then in the script.php file I have this:

<?php  
$user =& JFactory::getUser();
echo "This is the user: ".$user;
?> 

If I don’t put any Joomla framework code in script.php it works fine. But the purpose of doing this is that I need to use the Joomla framework and hence the whole point of creating a component. But I still don’t understand how I need to structure the Joomla component so I don’t get the Class 'JFactory' not found error?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T20:06:04+00:00Added an answer on June 8, 2026 at 8:06 pm

    Didn’t end up taking too long in the end. The only file that is required is the default.php, so you can delete the script.php and other odd files you have in there.

    Default.php

    <?php
    defined('_JEXEC') or die('Restricted access');
    
    //$document =& JFactory::getDocument();
    //$document->addScript("https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js");
    $user =& JFactory::getUser();
    ?>
    
    <div id="wrapper">
        <div id="quote" style="display:none; padding-bottom:10px;">
            <?php 
              echo "<p>This is your username: " . $user->username . "</p>"; 
              echo "<p>This is your realname: " . $user->name . "</p>"; 
              echo "<p>This is your user ID: " . $user->id . "</p>";
            ?>
        </div>
        <input type="submit" id="generate" value="Generate!">
    </div>
    
    <script type="text/javascript">
    $(document).ready(function(){
         $("#generate").click(function(){
              $("#quote").show();
         });
    });
    </script>
    

    I have commented out the jquery reference in the code, seeing as the widgetkit is already loading a copy of it, but kept it there just incase.

    Instead of loading another file, what this does is, it hides #quote div tag and when the button is clicked, it reveals it with the data inside it. In this one, I have added realname and user ID just incase.

    Hope this helps.

    Regards

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still having problems with figuring out how to create winforms in a
I'm having trouble figuring out how I can count the number of logged-in users
I am still having problems with this so I can going to ask for
I tried several solutions found on other posts but still having problems to autoresize
I ve looked at the JSoup Selector Overview documentation but I'm still having problems.
I'm still new to code igniter and I'm having problems getting the login system
I'm still entangled in error handling problems. After having read and tried lots of
Still having issues with this problem. Please help if you can. So I am
I'm having trouble figuring out how to solve this issue. I have a file
I'm still having problems with loading the style sheet for these pages. Works fine

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.