Thank you for your reply. I wasnt totally honest with you :)
My somefile.php is included in index.php?kom=somefile. At the end of index.php file I have echo $htmlOutput function and in somefile.php I append HTML to global $htmlOutput variable. At the end it gets echoed by index.php So, simplified, my somefile.php looks like this: switch($task) { case ajaxcheck: //Check if enetred value ($POST[name]) already exists in DB. If so put $msg=1 or $msg=0 and echo it fAjaxCheck(); break; case normalcheck: fNormalCheck(); break; } When I use this jQuery code: $.post( "index.php?kom=somefile&task=ajaxcheck\", {ime: $(\"#ime\").val()}, function(data){ alert(data); }); as a result I get much more than $msg variable I've put exit(); at the end of fAjaxCheck(); so that echo $htmlOutput doesn't run (at the end on index.php). It works fine if I approach to URL (index.php?kom=somefile&task=ajaxcheck) directly. I get my $msg value printed without any other HTML, but if I go over jQuery POST call I get bunch of HTML tags back. Sorry if Im being boring with this, cause I know I could create separate file, but I would like to solve this this way because I have included classese for DB, inputFiltering in index.php etc. Thank you ver, very much On Sep 18, 7:36 pm, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]> wrote: > Before giving practical solutions, I'd like to invite you to think > about this question. Is this a server-side or a client-side matter? In > other words, does this have to do with the server-response or the > server-request? > > It's obvious that it's server-side because it has to do with the > server-response. How do you get the server to send only the value you > need? > > The reply above gives you a valid solution in PHP. Another solution > would be checking the $_GET[] variable to see whether "task" is set to > "checkname" and respond according that info. > > if ($_GET['task'] == 'checkname') { > // print var;} > > else { > // print page; > > } > > A more sophisticated way of handling this would be using the switch- > statement. > > switch ($_GET['task']) { > case 'checkname': { > // print var;} break; > > case 'page': // fall-through > default: { > // print page > > } break; > } > > Or you simply create a new file that explicitly handles AJAX requests. > > HTH, > Rick > > luigi7up wrote: > > Hello everyone, > > > Is it possible to send ajax call for somefile.php and get just value > > of one php variable generated by that server > > > script? > > > Example: > > > $.post( blog.php?task=checkname, > > > {ime:$(\"#ime\").val()}, > > function(msg){ > > alert(msg); > > }); > > > This ajax call will get whole page ( blog.php?task=checkname) as a > > result but I want value of just one variable. > > > I know I could create a separate file "ajaxCheck.php" that would > > return HTML I could reuse in my javaScript > > > but I want to solve this this way. > > > Im probbably using wrong method POST & GET. Should I be using jSON?! > > How do I use it for this purposes > > > Thank you > > > Luka