我有一個頁面的形式與action="/profile"
,我想做一個Ajax代碼,使其更新,而無需刷新頁面,無需轉到該頁面。任何想法,我如何去做這件事,或者如果我真的做對了或什麼?使用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
感謝任何人幫助我
有沒有人有任何線索如何做到這一點? – EasyBB