Hello everyone, I think Ill go go nuts! I already posted something about problem Im facing with but I didn't get the right answer so Ill try again by expaining my problem further.
My PHP website is organised in following manner: MAin file is index.php and it includes other files. So, my "components" are included by setting URL for example index.php? kom=gallery. Everything in gallery file (and all others) is printed into global variable $htmlOutput.= and is echoed at the end of execution of index.php. Gallery file, for example, runs switch($_POST[task]) and calls different functions depending on value of ($_POST[task]. One function outputs HTML form where you can input username. I want to check if username is already taken by querying my database. Normal check would be by pressing submit button but I want ajax to check availability and to output message. For ajax check I've set a function fAjaxCheck() that is triggered by $_POST[task] = ajaxCheck. That function looks like this ajaxCheck() { //Find if DB has that us ername //if database returns so mething it means tahat usuername is already taken if(empty($result)) { //Username taken echo "no"; exit; } else { //Username ok echo "yes"; exit; } } I get my index php page html as a result!!! This is jquery Im using: $.post(\"index.php?kom=gallery\", { task:'is_username_taken',username: $('#username').val()}, function(data){ alert(data); }) I can't understand why do I keep getting this result. exit() at the and of if/else should stop script from working and my $htmlOutput variable at the end of index.php sholud never be echoed. Do you have any idea how to solve this? Why do I get all that html when I shold be geting only things from my ajaxCheck() function, thing I explicitly echo!? Thank you and sory for the trouble...