问题是我无法在不重新加载的情况下将数据插入我的数据库
我已经在没有 note_sql.js
的情况下对其进行了测试,我的 note_sql.php
工作正常,但我的 js
文件似乎有问题 body 可以给我指明正确的方向,那就太好了
索引.php
<form id="noteform" action="note_sql.php" method="POST">
<input type="text" name="note"></input>
<input id="sub" type="submit" value="Save Note" />
</form>
<span id="result_note"><span>
<script type ="text/javascript" src="jquery/note_sql.js"></script>
note_sql.js
$("#sub").click(function(){
var data = $("#noteform: input").serializeArray();
$.post($("#noteform").attr("action"),data,function(info){$("result_note").html(info); });
clearInput();
});
$("#noteform").submit(function(){
return false;
});
function clearInput(){
$("#noteform :input").each(function(){
$(this).val('');
});
}
最佳答案
使用 Jquery Ajax 的工作代码如下: 请将 ID 添加到注释表单元素:
<pre>
<script>
$(document).ready(function () {
$("#sub").click(function () {
var name = $("#note").val();
var message = $("#message").val();
$.ajax({
type: "post",
url: "note_sql.php",
data: "name=" + name,
success: function (data) {
alert(data);
}
});
});
});
</script>
</pre>
关于php - 在不重新加载页面的情况下将数据发布到sql数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33996019/