我在一个页面上有一个表单action="/profile"
,我正在尝试制作一个 Ajax 代码以使其在不刷新页面且无需转到该页面的情况下更新。关于我如何做这件事或者我是否真的做对了或什么的任何想法?
$(function() {
$('.error').hide();
$("#submit").click(function() {
// validate and process form here
$('.error').hide();
var stat = $("#profile_field_13_5").val();
if (stat == "") {
$("#name_error").show();
$("#profile_field_13_5").focus();
return false;
}
var dataString = 'stat='+ stat ;
$.ajax({
type: "POST",
url: "/profile.php",
data: dataString,
success: function() {
$('#statsucces').show();
window.setTimeout("closeSuccess();", 10000);
function closeSuccess(){
document.getElementById("statsuccess").style.display=" none";
}
});
});
return false;
});
});
这是我试图用来进行状态更新的输入字段
#profile_field_13_5
表单动作再次是/profile.php
感谢任何帮助我的人