onclick -> mysql query -> javascript; same page

后端 未结 4 1261
自闭症患者
自闭症患者 2021-01-29 03:41

I need button to begin a mysql query to then insert the results into a javacript code block which is to be displayed on the same page that the button is on. mysql queries come f

4条回答
  •  情歌与酒
    2021-01-29 04:26

    You need to use a technology called AJAX. I'd recommend jQuery's .ajax() method. Trying to do raw XHR is painful at best.

    Here is how you'll want to structure your code:

    1. Load the page.
    2. User chooses an option.
    3. An onChange listener fires off an AJAX request
    4. The server receives and processes the request
    5. The server sends back a JSON array of options for the dependent select
    6. The client side AJAX sender gets the response back
    7. The client updates the select to have the values from the JSON array.

    Basically, HTTP is stateless, so once the page is loaded, it's done. You'll have to make successive requests to the server for dynamic data.

提交回复
热议问题