Bugs in search fixed. Organized JSON passing (PHP-Javascript)

(try the updated code and tell me if you see any bugs)