You need to have a backend script to execute the query - JavaScript, which is a fully client-side language, has nothing to do with what happens to your MySQL server.
What you need to do is pass the parameters that you want in your request to any server language that you use through AJAX, and the script create and process the request as you wish.
DO NOT create a request in javascript and send it to the server - this is VERY unsafe, as it allows any user to fulfill any requests that they want.
source share