I have nothing against jquery, but I never got around to using it, and for what you want to do, a simple AJAX call would be so easy, if it were me, I wouldn't want to learn a whole new environment.
Your Javascript does a couple of things:
- instantiates a built-in JS object called XMLHttpRequest()
- defines a function that will be called when the results are sent back from the server
- sends a request to a PHP script on the server
- checks for a ready code from the server to determine when the data is ready for your function to use
You just need to use the correct syntax, as shown in the link I provided above.
On the server side, you have to write that PHP script, that results in
echoing the desired data back, which will be used by the function that you defined in the calling JS script.
Once you see how it works, it's simple to code and use. The JS code may look daunting at first, primarily because IE browsers don't use the same naming conventions as Mozilla browsers, so you have to test for which browser is making the call, and the fact that it has to check for a return code from the server, indicating that the data is ready.