More ajax edits, javascript file created

Made some more edits to ajax but still has an error. Javascript file
created as well to reduce redundancy.