1

I am new to JavaScript. I'm creating my module. I'm trying to send data from an html form. I Can not use com_ajax...I create new class in helper.php.

public static function getAjax() {

    jimport('joomla.application.module.helper');
    $input  = JFactory::getApplication()->input;
    $module = JModuleHelper::getModule('mymodulename');
    $params = new JRegistry();
    $params->loadString($module->params);
}

I need to send data to default.php.

I wrote a script to send data to a mod_name.php. JS HERE:

<script>
 jQuery.noConflict();
   function function1() {
    var data = jQuery("lol").serialize();
    jQuery.ajax({
        url: "index.php?option=com_ajax&module=auction&method=post&format=json", 
        type: "POST",
        data: data, 
        success: function(data){ 
            alert(data); 
        }
    });
};
</script>

FOR

<form method="post" action="this.form.submit();" name="form1" id="lol">
    <input type="text" name="price" onclick="function1();">
</form>

Did I do the right thing? And how can I get data in default.php?

  • why you can't use com_ajax? Same time your ajax call is to com_ajax... – FFrewin Jun 11 '17 at 15:40
  • Your PHP function name is getAjax. The method in the URL needs to be the function name but without Ajax, so in your case, it should be method=get – Lodder Jun 11 '17 at 17:40
  • Look at this answer for an example of ajax in a module without com_ajax: joomla.stackexchange.com/questions/20578/… Someone else wanted to do ajax in a module without using com_ajax a couple of months ago - is this a school exercise or something? – jamesgarrett Jun 11 '17 at 23:33
1

The problem is in your url, the correct is:

jQuery.ajax({
        url: "index.php?option=com_ajax&module=auction&method=FUNCTIONNAME&format=json", 
        type: "POST",
        data: data, 
        success: function(data){ 
            alert(data); 
        }
    });

in your case, the FUNCTIONNAME will be get.

And your function, in helper of module, must end with "Ajax". Ex.

public myFunctionAjax(){
  //Do something
}

in this case, url will be index.php?option=com_ajax&module=MODULENAME&method=myFunction&format=json.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.