好的,我已经看到很多关于提交表单而不刷新的方法,我觉得有几种方法可以通过提交或仅使用按钮(差异/最佳?)来做到这一点,尽管搜索了无数帖子,但我仍然遇到问题. 所以:
$(function() {
$('form').on('submit', function(e) {
e.preventDefault();
var privacy = $('input:radio[name=privacy]:checked').val();
var invites = $('input:radio[name=invites]:checked').val();
var posts = $('input:radio[name=posts]:checked').val();
var dataString = 'privacy=' + privacy + '&invites=' + invites + '&posts=' + posts;
alert(dataString);
$.ajax({
type: "POST",
url: "editOptions.php",
data: dataString,
success: function() {
$('#admin').append("<div id='message'</div>");
$('#message').html("Changes Saved");
}
});
return false;
});
});
和:
<form action="" method="post" name="editOptions">
Privacy
<input type="radio" name="privacy" id="privacy" value="public"
<?php if($privacy == "public") { ?>checked="checked"<?php } ?>>
Public
<input type="radio" name="privacy" id="privacy" value="private"
<?php if($privacy == "private") { ?>checked="checked"<?php } ?>>
Private
Invites
<input type="radio" name="invites" id="invites" value="adminonly"
<?php if($invite == "adminonly") { ?>checked="checked"<?php } ?>>
Admin Only
<input type="radio" name="invites" id="invites" value="everyone"
<?php if($invite == "everyone") { ?>checked="checked"<?php } ?>>
Everyone
Posts
<input type="radio" name="posts" id="posts" value="adminonly"
<?php if($post == "adminonly") { ?>checked="checked"<?php } ?>>
Admin Only
<input type="radio" name="posts" id="posts" value="everyone"
<?php if($post == "everyone") { ?>checked="checked"<?php } ?>>
Everyone
<button>Save Changes</button>
</form>
所以只是一个带有 3 组 2 个单选按钮的表单。因此,我认为问题出在许多教程和帖子中,当您“提交”或单击“按钮”时,我结合了要做什么,但也许其他人可以看到我错过的简单内容。
泰
编辑 editOptions 以防万一
<?php
include 'config.php';
$privacyX = $_POST['privacy'];
$invitesX = $_POST['invites'];
$postsX = $_POST['posts'];
$groupAd = $_POST['groupName'];
$sql = "UPDATE `options` SET privacy='$privacyX', invite='$invitesX', post='$postsX' WHERE adminGroup = '$groupAd'";
if(!mysql_query($sql, $link))
{
die('Error: ' . mysql_error());
}
mysql_close($link);
?>