Is there an article (tutorial) on how to create your own Ajax module?

For Joomla! 3.x Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Post Reply
adrian24
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Thu Nov 06, 2014 9:55 am

Is there an article (tutorial) on how to create your own Ajax module?

Post by adrian24 » Sat Oct 16, 2021 6:59 am

Hi,

Sorry for my English,

Is there any article (tutorial) on how to create your own Ajax module? I trying develop my own module with Ajax but I have a problemm. The answer list is not displayed properly.

Thank You for any help.

Regards Adrian

User avatar
AMurray
Joomla! Champion
Joomla! Champion
Posts: 7246
Joined: Sat Feb 13, 2010 7:35 am
Location: Australia

Re: Is there an article (tutorial) on how to create your own Ajax module?

Post by AMurray » Sat Oct 16, 2021 8:08 am

I'm not a coder but there's more to it than simply AJAX.
Refer to https://docs.joomla.org/J3.x:Creating_a ... sic_Module for creating modules in Joomla.
Regards - A Murray

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 28307
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Is there an article (tutorial) on how to create your own Ajax module?

Post by Per Yngve Berg » Sat Oct 16, 2021 9:12 am

Mod. Note: Not related to extensions. Relocating to the coding forum

adrian24
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Thu Nov 06, 2014 9:55 am

Re: Is there an article (tutorial) on how to create your own Ajax module?

Post by adrian24 » Sat Oct 16, 2021 10:05 am

At this moment I create files:

mod_register.php with the code:

Code: Select all

<?php
 defined('_JEXEC') or die;
/**
* File mod_hello_ajax_world.php
* Created 1/17/14 12:29 PM
* Author Matt Thomas | matt@betweenbrain.com | http://betweenbrain.com
* Support https://github.com/Joomla-Ajax-Interface/Hello-Ajax-World-Module/issues
* Copyright Copyright (C) 2013 betweenbrain llc. All Rights Reserved.
* License GNU General Public License version 2, or later.
*/
// Include the helper.
require_once __DIR__ . '/helper.php';
// Instantiate global document object
$doc = JFactory::getDocument();

$loadJquery = $params->get('loadJquery', 1);
$format     = $params->get('format', 'debug');

// Load jQuery
if ($loadJquery == '1') {
	$doc->addScript('//code.jquery.com/jquery-latest.min.js');
}

$js = <<<JS



(function ($) {
$(document).on('keyup', 'input[type=text]', function () {
var value = $('input[name=nip_sprzedawcy]').val(),
request = {
'option' : 'com_ajax',
'module' : 'register',
'data' : value,
'format' : 'raw'
};
$.ajax({
type : 'POST',
data : request,
success: function (response) {
$('.lista_nipow_sprzed').show();
$('.lista_nipow_sprzed').html(response);
//alert(value);
},
error: function(response){
	$('.lista_nipow_sprzed').html('Wystąpił błąd!');
}
});

$(".lista_nipow_sprzed").click ( function(){
	
	$('#nip_sprzedawcy').val($(".lista_nipow_sprzed").attr('data-value'));
});

$(".lista_nipow_sprzed").on("click", "a", function(e){
    e.preventDefault();
    var value = $('#nip_sprzedawcy').parent(); 
    
    $("#nip_sprzedawcy").val(value); 
});




return false;
});
})(jQuery)


JS;

$doc->addScriptDeclaration($js);
require JModuleHelper::getLayoutPath('mod_register');

?>
helper.php with the code:

Code: Select all

<?php

class modRegisterHelper
{
	public static function getAjax()
	{
		$baza_danych = JFactory::getDbo();
		$input = JFactory::getApplication()->input;
		$data = $input->get('nip_przedawcy');
		
		//preg_match
		if(preg_match('/^[0-9]{0,}/', $data)) //(preg_match('/^([A-Za-z]?!0-9){0,}$/', $data))
		{
			//echo"Szukasz miejscowosci!";
			$data4 = $data;
			$query_auto2 = "SELECT NIP, Nazwa FROM mytable WHERE NIP LIKE '".$data4."%' LIMIT 0, 10;";
			$baza_danych->setQuery($query_auto2);
			$baza_danych->query();
		
			//echo $query_auto;
			$sprzedawcy = $baza_danych->loadObjectList();
		
			foreach($sprzedawcy as $sprzedawcy)
			{//ustaw_miejsce($miejsce->miejscowosc);
				
				//$zmienna = (string)$miejsce->miejscowosc;
				
				echo"<li class=\"lista_filt2\" data-value=\"$sprzedawcy->NIP\" onclick=\"set_item('$sprzedawcy->NIP'+' - '+\'$sprzedawcy->Nazwa\');\" >$sprzedawcy->NIP ($sprzedawcy->Nazwa)</li>";
			}
		}
	}
}

?>
tmpl/default.php

Anyone can help me what am I doing wrong?

https://flex-elektronarzedzia.pl/gwaran ... estruj.php

If You want to see the form. You have to be logged in. Register is free

Regards Adrian

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2019
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Is there an article (tutorial) on how to create your own Ajax module?

Post by SharkyKZ » Sat Oct 16, 2021 11:34 am

modRegisterHelper::getAjax() should be returning data, not outputting it.

User avatar
Per Yngve Berg
Joomla! Master
Joomla! Master
Posts: 28307
Joined: Mon Oct 27, 2008 9:27 pm
Location: Romerike, Norway

Re: Is there an article (tutorial) on how to create your own Ajax module?

Post by Per Yngve Berg » Sat Oct 16, 2021 12:03 pm



Post Reply

Return to “Joomla! 3.x Coding”