I have a button that should do an Ajax call to a servlet in order to create/write a Textfile in a certain Directory. How do i transfer the variable "text" to the servlet and does the Ajax call look right?
You've hard-coded the URL to use localhost. That means it cannot work anywhere else but your local machine. You should be using a URL that works everywhere. In order to help you figure out what that is, we need some more context. Since you mention Servlets, I assume that this is a Java web application in which the view is provided by a JSP in the same web app? If so, see below. If not, tell us what you've got going on.