You need to print something with php. I don't understand what you are trying to do. You can use php inside javascript for templating but I suggest you use ajax.
I would use jQuerys .ajax() function on the javascript side and echo json_encode($result_array)
on the php side.