I have an ajax function and while caling that function the php code will execute and check if any rows with the given data is present in the table. If there is no data I would like to display an alert. right now I can display a div with the error message but I could not get the out put such as
echo "<script> alert('error'); </script>";
You can not stick JavaScript on the page using innerHTML since it will not be evaluated. What you would need to do is parse out the JavaScript code and shove it into eval(). OR use a framework that does it for you like jQuery.
It is better to develop a framework on the client that does not rely on this eval. A better messaging system would work.
Basic JavaScript idea: