I have a jquery-ajax function that sends data to a php script and the problem is with the return value, it returns the whole page instead of single value.
Thank you
So when you have this on your index.php
at the beginning?:
If this script is outputting further text then of course this will also be recieved by the Ajax call. You can put exit()
after the echo to prevent the script from being processed further:
if (isset($_POST["testAjax"])) {
echo $_POST["testAjax"];
exit();
}
Also use dataType: 'text'
as the value you return is obviously not HTML.
Or as others suggest, create a new page that is responsible for dealing with the Ajax request. If you are doing more than just outputting the received value (i.e. more complex operations) you should do this anyway.