【发布时间】:2016-03-11 11:40:39
【问题描述】:
您好,我正在尝试从与 php 代码相同页面上的表单更新数据库中的数据,而无需重定向/重新加载页面。
我试过这个教程,但没有用:http://www.formget.com/form-submit-without-page-refreshing-jquery-php/
更新代码:
<?php
include "db.php";
session_start();
$value=$_POST['name'];
$query = mysqli_query($connection,"UPDATE users SET profiel='$value' WHERE username='$_SESSION['user']'");
?>
Profilecomplete.js:
$(document).ready(function() {
$("#submit").click(function() {
var name = $("#name").val();
if (name == '') {
alert("Insertion Failed Some Fields are Blank....!!");
} else {
// Returns successful data submission message when the entered information is stored in database.
$.post("config/profilecomplete.php", {
value: name
}, function(data) {
alert(data);
$('#form')[0].reset(); // To reset form fields
});
}
});
});
形式:
<form method="POST" id="form">
<div class="input-field col s6">
<input id="name" type="text" class="validate">
<label for="name">Value</label>
</div>
<button type="submit" id="submit" class="btn-flat">Update</button>
</form>
【问题讨论】:
-
你有这方面的例子/教程吗?
-
你能用你正在使用的更多代码来编辑你的问题吗?我还没有阅读该教程,但我认为使用了某种形式的 jQuery ajax,而且我敢肯定,我不是唯一一个想按照整个教程来回答您的问题的人。
-
谢谢。进一步的问题,您是否在控制台中收到任何错误或页面上可能出现 PHP 错误?
-
发帖前我没有第一件事检查;)
-
您正在寻找的是
SPAen.wikipedia.org/wiki/Single-page_application 或至少它的组成部分。
标签: javascript php jquery html ajax