Calling AJAX in custom module - without components help

186 views
Skip to first unread message

1996wiz...@gmail.com

unread,
Apr 14, 2017, 5:10:35 PM4/14/17
to Joomla! General Development
I can not use -

com_ajax
Any other components

My goal is to send POST data when checkbox is 'checked' using jquery AJAX

I've mod_test module.

default.php

<form method="post" action="this.form.submit();" name="form1">
<input type="checkbox" name="checkboxList[]" onclick="function1();" value="1">value1</input>
<input type="checkbox" name="checkboxList[]" onclick="function1();" value="2">value2</input>
<input type="checkbox" name="checkboxList[]" onclick="function1();" value="3">value3</input>
</form>

<script>
function function1() {
var data = $("[name='form1']").serialize();
$.ajax({
url: "modules/mod_test/mod_test.php",
type: "POST",
async: true,
cache: false,
data: data,
success: function(data){
alert(data);
}
});
}
</script>


1. Is my jquery (for ajax call) correct?
2. How can I pass POSTED data to my modules mod_test.php? Is the url correct? Is there an alternative?
- I understand, that every joomla file has [i]defined('_JEXEC') or die;[/i], but even if I comment it out - I dont get ajax post data if I do print_r($_POST); Why? I also understand its security issue. But this makes me wonder.
3. Is there a way of writing some kind of function or something, to use only module and send POSTED data to mod_test helper.php/mod_test.php using AJAX? (without writing component)

I'm open to ideas. Please, don't ask why I dont use components. I'm open for some creative brain-storming.

Mark Dexter

unread,
Apr 14, 2017, 5:53:22 PM4/14/17
to Joomla! General Development
Why not use the standard com_ajax component? This is what it is designed for -- to let you make ajax calls from a module. See https://docs.joomla.org/Using_Joomla_Ajax_Interface.


--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send an email to joomla-dev-general@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

1996wiz...@gmail.com

unread,
Apr 14, 2017, 6:12:36 PM4/14/17
to Joomla! General Development
As I mentioned, com_ajax is a component therefore - not an option for me. I'm looking for some alternative. Isn't there a possibility avoid components (even if it's pain in ass to achieve it)?
To post to this group, send an email to joomla-de...@googlegroups.com.

Mark Dexter

unread,
Apr 14, 2017, 6:16:36 PM4/14/17
to Joomla! General Development
I'm not sure what you mean by "avoid components". The com_ajax is sitting there in every Joomla installation. You don't need to do anything to use it. It is just a vehicle for allowing you to call methods in your module's helper without needing to re-invent the wheel. Joomla is set up so that a URL is directed to a component, not to a module. It seems like you are trying to "swim upstream" instead of taking advantage of how Joomla is designed to solve this issue.

To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsubscribe@googlegroups.com.

To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send email to joomla-dev-general@googlegroups.com.

1996wiz...@gmail.com

unread,
Apr 15, 2017, 2:15:54 AM4/15/17
to Joomla! General Development
That might be true, but I am really looking for the alternative right here. I'm pretty sure this has be done somehow in the past. Com_ajax was introduced only in 3.2+ versions. What did ppl do before? That's what I want to find out. It's more like a research 
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send an email to joomla-de...@googlegroups.com.
Visit this group at https://groups.google.com/group/joomla-dev-general.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Joomla! General Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email to joomla-dev-general+unsub...@googlegroups.com.
To post to this group, send email to joomla-de...@googlegroups.com.

Hannes Papenberg

unread,
Apr 15, 2017, 4:05:44 AM4/15/17
to joomla-de...@googlegroups.com
Before com_ajax, people either created a proper component for this or
they hacked it by putting a seperate PHP file into their modules folder,
introducing lots of security issues in the process.

Are you trying to develop a module or are you just doing research? If
you are developing, use com_ajax. That is the way it is supposed to be
done and to be blunt: Asking for a different solution for a fourth time
will not get you any better answers.

Hannes

Am 15.04.2017 um 08:15 schrieb 1996wiz...@gmail.com:
> That might be true, but I am really looking for the alternative right
> here. I'm pretty sure this has be done somehow in the past. Com_ajax was
> introduced only in 3.2+ versions. What did ppl do before? That's what I
> want to find out. It's more like a research
>
> On Saturday, April 15, 2017 at 1:16:36 AM UTC+3, Mark Dexter wrote:
>
> I'm not sure what you mean by "avoid components". The com_ajax is
> sitting there in every Joomla installation. You don't need to do
> anything to use it. It is just a vehicle for allowing you to call
> methods in your module's helper without needing to re-invent the
> wheel. Joomla is set up so that a URL is directed to a component,
> not to a module. It seems like you are trying to "swim upstream"
> instead of taking advantage of how Joomla is designed to solve this
> issue.
>
> On Fri, Apr 14, 2017 at 3:12 PM, <1996wiz...@gmail.com
> <javascript:>> wrote:
>
> As I mentioned, com_ajax is a component therefore - not an
> option for me. I'm looking for some alternative. Isn't there a
> possibility avoid components (even if it's pain in ass to
> achieve it)?
>
> On Saturday, April 15, 2017 at 12:53:22 AM UTC+3, Mark Dexter wrote:
>
> Why not use the standard com_ajax component? This is what it
> is designed for -- to let you make ajax calls from a module.
> See https://docs.joomla.org/Using_Joomla_Ajax_Interface
> <https://docs.joomla.org/Using_Joomla_Ajax_Interface>.
> joomla-dev-gene...@googlegroups.com.
> To post to this group, send an email to
> joomla-de...@googlegroups.com.
> Visit this group at
> https://groups.google.com/group/joomla-dev-general
> <https://groups.google.com/group/joomla-dev-general>.
> For more options, visit
> https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the
> Google Groups "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to
> joomla-dev-gene...@googlegroups.com <javascript:>.
> To post to this group, send email to
> joomla-de...@googlegroups.com <javascript:>.
> <https://groups.google.com/group/joomla-dev-general>.
> For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to joomla-dev-gene...@googlegroups.com
> <mailto:joomla-dev-gene...@googlegroups.com>.
> To post to this group, send email to joomla-de...@googlegroups.com
> <mailto:joomla-de...@googlegroups.com>.
Message has been deleted

1996wiz...@gmail.com

unread,
Apr 16, 2017, 4:19:30 AM4/16/17
to Joomla! General Development
Can you please give me an example on "hacked by putting seperate php file into their modules folder"?
>                 To post to this group, send an email to
>                 joomla-de...@googlegroups.com.
>                 Visit this group at
>                 https://groups.google.com/group/joomla-dev-general
>                 <https://groups.google.com/group/joomla-dev-general>.
>                 For more options, visit
>                 https://groups.google.com/d/optout
>                 <https://groups.google.com/d/optout>.
>
>
>         --
>         You received this message because you are subscribed to the
>         Google Groups "Joomla! General Development" group.
>         To unsubscribe from this group and stop receiving emails from
>         it, send an email to
>         joomla-dev-general+unsub...@googlegroups.com <javascript:>.
>         To post to this group, send email to
>         joomla-de...@googlegroups.com <javascript:>.
>         Visit this group at
>         https://groups.google.com/group/joomla-dev-general
>         <https://groups.google.com/group/joomla-dev-general>.
>         For more options, visit https://groups.google.com/d/optout
>         <https://groups.google.com/d/optout>.
>
>
> --
> You received this message because you are subscribed to the Google
> Groups "Joomla! General Development" group.
> To unsubscribe from this group and stop receiving emails from it, send

Hannes Papenberg

unread,
Apr 17, 2017, 3:40:24 AM4/17/17
to joomla-de...@googlegroups.com
It is a simple standalone PHP script in the modules folder that you
would call directly via JS. But since that is not inside the Joomla
framework, you don't have any of the luxuries that the framework
provides and none of the security benefits. The "hacked" was refering
more to the fact that people found a nasty workaround. The security
issues are mainly in that PHP file, which often enough does not do all
necessary checks to prevent SQL injections and similar stuff.

Am 15.04.2017 um 11:04 schrieb 1996wiz...@gmail.com:
> "they hacked it by putting a seperate PHP file into their modules folder,
> introducing lots of security issues in the process." This is the one I
> was looking for. Can you please be so kind and give me an example of
> this method? It would mean alot.
>
> On Saturday, April 15, 2017 at 11:05:44 AM UTC+3, Hannes Papenberg wrote:
>
> Before com_ajax, people either created a proper component for this or
> they hacked it by putting a seperate PHP file into their modules
> folder,
> introducing lots of security issues in the process.
>
> Are you trying to develop a module or are you just doing research? If
> you are developing, use com_ajax. That is the way it is supposed to be
> done and to be blunt: Asking for a different solution for a fourth time
> will not get you any better answers.
>
> Hannes
>
> > joomla-dev-gene...@googlegroups.com
> <javascript:>.
> > To post to this group, send an email to
> > joomla-de...@googlegroups.com.
> > Visit this group at
> > https://groups.google.com/group/joomla-dev-general
> <https://groups.google.com/group/joomla-dev-general>
> >
> <https://groups.google.com/group/joomla-dev-general
> <https://groups.google.com/group/joomla-dev-general>>.
> > For more options, visit
> > https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>
> > <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >
> >
> > --
> > You received this message because you are subscribed to the
> > Google Groups "Joomla! General Development" group.
> > To unsubscribe from this group and stop receiving emails from
> > it, send an email to
> > joomla-dev-gene...@googlegroups.com
> <javascript:> <javascript:>.
> > To post to this group, send email to
> > joomla-de...@googlegroups.com <javascript:>.
> > Visit this group at
> > https://groups.google.com/group/joomla-dev-general
> <https://groups.google.com/group/joomla-dev-general>
> > <https://groups.google.com/group/joomla-dev-general
> <https://groups.google.com/group/joomla-dev-general>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>
> > <https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>>.
> >
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Joomla! General Development" group.
> > To unsubscribe from this group and stop receiving emails from it,
> send
> > an email to joomla-dev-gene...@googlegroups.com
> <javascript:>
> > <mailto:joomla-dev-gene...@googlegroups.com
> <javascript:>>.
> > To post to this group, send email to joomla-de...@googlegroups.com
> <javascript:>
> > <mailto:joomla-de...@googlegroups.com <javascript:>>.
Reply all
Reply to author
Forward
0 new messages