[SOLVED]Joomla Ajax with Mootools 1.2.4 not working

For Joomla! 1.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Locked
User avatar
pheadrus
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Wed Dec 19, 2007 7:11 pm
Location: Istanbul

[SOLVED]Joomla Ajax with Mootools 1.2.4 not working

Post by pheadrus » Wed May 25, 2011 3:24 pm

Hi,
i have made an module which have a form and some form elements. For the two of the form elements, I need to run an ajax request.
I have checked that my Mootools upgrade plugin is enabled.(running Mootools 1.2.4)
Then, I simply added the script to my module:

Code: Select all

$document->addScript(JURI::root(true) . '/modules/mod_xxxara/assets/js/ajaxscript3.js');
The ajaxscript3.js is like:

Code: Select all

window.addEvent('domready', function() {

  /* ajax replace element text */
  $('sehir').addEvent('change', function(event) {
    //prevent the page from changing
    event.stop();
    //make the ajax call, replace text
    var req = new Request.HTML({
      method: 'get',
      url: 'http://www.ixxalar.net/modules/mod_xxxara/ajaxcalling.php',
      data: { 'sehir' : $('sehir').getSelected().get('value') },
      update: $('details'),
    onComplete: function(response) { $('details').set('html', response); }
    }).send();
  });
});
And here is my ajaxcalling.php:

Code: Select all

<?

$connect=mysql_connect('localhost', 'bilxxi', 'xx1911');
//To send utf8 data to MySql - needed if you need to inject utf8 data for search
mysql_query("SET character_set_client=utf8", $connect);
mysql_query("SET character_set_connection=utf8", $connect);

//To read utf8 data from MySql - needed if your result set contains utf8 data
mysql_query("SET character_set_results=utf8", $connect); 

$ID=$_REQUEST['sehir[0]'];

$result = mysql_db_query('bilxxa', "SELECT * FROM `ilce` WHERE `il_id` =".$ID." ORDER BY `ilce`.`ilce_isim` asc");
echo '<li><label class="" id="" for="ilce"><b> İlçe </b></label><select class="" style="width:140px" id="ilce" name="ilce"><option value="all" selected="selected">Tümü</option>';
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))
    {
     echo "<option value=\"".$row['id']."\">".$row['ilce_isim']."</option>";
    }
echo '</select></li>';

mysql_close($connect);
?>
If I test my ajax request with Firebug, I see that the request ends with empty response(result). I have double checked the php file which normally gets some data.

What should I do to get response from ajax request? I am looking for an answer for 2 hours on net. If you have an idea, please tell me. I really really appreciate..
Last edited by pheadrus on Fri May 27, 2011 8:02 am, edited 1 time in total.

User avatar
pheadrus
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Wed Dec 19, 2007 7:11 pm
Location: Istanbul

Re: Joomla Ajax with Mootools 1.2.4 not working

Post by pheadrus » Fri May 27, 2011 7:58 am

Ok, I solved my own case :) My ajax request was not proper, Mootools version 1.1.2 have a different pattern, so I changed the ajax request from 'Request.HTML' to 'Ajax' and now it's working..
Hope this helps if anyone falls into same mistake like me :)

User avatar
pheadrus
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Wed Dec 19, 2007 7:11 pm
Location: Istanbul

Re: Joomla Ajax with Mootools 1.2.4 not working

Post by pheadrus » Fri May 27, 2011 8:02 am

P.S: I solved my problem, but still not understand why Request.HTML not worked (Mootools upgrade plugin was enabled+'Request.HTML' seemed a proper declaration for Mootools 1.2.4). Joomla's Mootools behavior is so strange although Joomla itself is best of the best web application for developers :)

ghazal
Joomla! Explorer
Joomla! Explorer
Posts: 343
Joined: Fri Aug 19, 2005 12:12 pm
Location: Out of my mind ...sometimes

Re: [SOLVED]Joomla Ajax with Mootools 1.2.4 not working

Post by ghazal » Fri May 27, 2011 11:37 am

Hi,
there are 2 issues here in your JS code:
from Mootools 1.2, I myself still find somehow difficult to decide when to use :
- Request or Request.HTML
- click or change
You can play with this very basic example :
http://jsfiddle.net/2GjKJ/

Check the Demos (for Moo 1.3) but as they are on jsfiddle, you can activate 1.2.5 to see what happens with this version
http://mootools.net/demos/

and stick to Mootools 1.2 and upward, there is no more support for Mootools 1.12 since around 2009.

User avatar
pheadrus
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Wed Dec 19, 2007 7:11 pm
Location: Istanbul

Re: [SOLVED]Joomla Ajax with Mootools 1.2.4 not working

Post by pheadrus » Fri May 27, 2011 12:00 pm

Thank you, your reply and jsfiddle link you gave will definitely help me to understand the usage of mootools.


Locked

Return to “Joomla! 1.5 Coding”