AJAX POST - how to use a js variable in PHP

后端 未结 3 1660
眼角桃花
眼角桃花 2021-01-28 18:48

The first time the page loads, there will not be anything in the POST data array. After it runs I want to be able to use whatever variable I send in the POST data in the PHP co

3条回答
  •  抹茶落季
    2021-01-28 19:26

    You can accomplish this by using an Ajax request. You have already loaded the JQuery library and have code that sends an Ajax request.

    Maybe you are looking for how to use the Ajax response on your client side script or how to send an Ajax request to the server on a client side event.

    Ajax is a way to communicate with the server without refreshing the page.

    So the simple answer to your question is that - no you don't need to reload the page to accomplish this.

    But, if you are ok (and more comfortable) with reloading the page, you can write JavaScript to fill a hidden field in a hidden form and use JavaScript to programmetically submit the form and handle everything in php on $_POST

提交回复
热议问题