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');
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();
});
});
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);
?>
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..