Hi, I'm working on one sites and having troubles with these:
I have tables catecogires and subcategories in database. When user add article, he
select categorie from select tag and under that tag appears another select tag
with subcategories of selected category. Code in jquery:
$("#ka").change(function(){
function PostaviPodatke(podaci){
$("#pka1").show();
var niz=podaci.split("+");
for(var i=0; i<niz.length; i++){
$('#pka').append(new Option(niz[i], niz[i]));
}
}
var nadkat=$("#ka").val();
$.post("uzmi_podkategorije.php", { nk: nadkat }, function(result){
PostaviPodatke(result);
});
});
Code of uzmi_podkategorije.php:
<?php
require_once ("includes/connection.php");
require_once ("includes/functions.php");
$nk1=trim(string_spreman_za_mysql($_POST['nk']));
$upit="SELECT p.naziv AS naziv
FROM podkategorije p, kategorije k
WHERE k.naziv='$nk1' AND k.id=p.nadkategorija";
$rez=mysql_query($upit);
$podkategorije="";
for($i=0; $i<mysql_num_rows($rez); $i++){
$red=mysql_fetch_array($rez);
$kat=stripslashes($red['naziv']);
$podkategorije = $podkategorije . $kat . "+";
}
echo $podkategorije;
?>
But this doesn't works. I tested script uzmi_podkategorije.php and it works fine, so
problem is in ajax.
How can I solve this?
Thanks in advance,
Amer