admin管理员组文章数量:1022727
Hello I have a select box in which when one item is selected a update_option event fires and get's the selected item's value and echo's it on the page without having to reloading the page. I've put a simple example below of what I am trying to do. I read that I have to use AJAX but I have no idea how this works.
<form action="" method="post">
<select name="SelectItem" size='4'>
<option>item1</option>
<option>item2</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(!empty($_POST["SelectItem"])){
update_option('SelectItem', $_POST["SelectItem"]);
}
}
echo get_option('SelectItem');
?>
Hello I have a select box in which when one item is selected a update_option event fires and get's the selected item's value and echo's it on the page without having to reloading the page. I've put a simple example below of what I am trying to do. I read that I have to use AJAX but I have no idea how this works.
<form action="" method="post">
<select name="SelectItem" size='4'>
<option>item1</option>
<option>item2</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(!empty($_POST["SelectItem"])){
update_option('SelectItem', $_POST["SelectItem"]);
}
}
echo get_option('SelectItem');
?>
Share
Improve this question
asked Feb 25, 2017 at 11:01
iani garthalskiiani garthalski
471 silver badge7 bronze badges
1 Answer
Reset to default -1Hi mate this is a really good tutorial for using Ajax in WordPress. Everything you'll need for what you want is basically covered. https://premium.wpmudev/blog/using-ajax-with-wordpress/
Essentially Ajax is just a custom jquery function in your JavaScript file that listens for an action on the page. It fires to the server to run the php function you specify, and then returns data from the server.
Hello I have a select box in which when one item is selected a update_option event fires and get's the selected item's value and echo's it on the page without having to reloading the page. I've put a simple example below of what I am trying to do. I read that I have to use AJAX but I have no idea how this works.
<form action="" method="post">
<select name="SelectItem" size='4'>
<option>item1</option>
<option>item2</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(!empty($_POST["SelectItem"])){
update_option('SelectItem', $_POST["SelectItem"]);
}
}
echo get_option('SelectItem');
?>
Hello I have a select box in which when one item is selected a update_option event fires and get's the selected item's value and echo's it on the page without having to reloading the page. I've put a simple example below of what I am trying to do. I read that I have to use AJAX but I have no idea how this works.
<form action="" method="post">
<select name="SelectItem" size='4'>
<option>item1</option>
<option>item2</option>
</select>
<input type="submit" name="submit" value="Submit">
</form>
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(!empty($_POST["SelectItem"])){
update_option('SelectItem', $_POST["SelectItem"]);
}
}
echo get_option('SelectItem');
?>
Share
Improve this question
asked Feb 25, 2017 at 11:01
iani garthalskiiani garthalski
471 silver badge7 bronze badges
1 Answer
Reset to default -1Hi mate this is a really good tutorial for using Ajax in WordPress. Everything you'll need for what you want is basically covered. https://premium.wpmudev/blog/using-ajax-with-wordpress/
Essentially Ajax is just a custom jquery function in your JavaScript file that listens for an action on the page. It fires to the server to run the php function you specify, and then returns data from the server.
本文标签: phphow to update and display an option without reloading the page
版权声明:本文标题:php - how to update and display an option without reloading the page 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://it.en369.cn/questions/1745574801a2156953.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论