0
我有我的AJAX形式,它的工作很棒。 我每次提交表格時都會返回<div id="message"></div>
內的結果,但當我有多個表格時會變得複雜。所以我想知道如果他們是一種方式來表明內部形式什麼<div>
返回消息。AJAX表單,傳遞返回消息
這裏是我的AJAX.js
$("form#ajaxForm").on("submit", function() {
var form = $(this),
url = form.attr("action"),
type = form.attr("method");
data = {};
form.find("[name]").each(function(index, value){
var input = $(this),
name = input.attr("name"),
value = input.val();
data[name] = value;
});
$.ajax({
url: url,
type: type,
data: data,
success: function(response) {
$("#message").html(response); //I would like to interactively switch the return div, from #message to like #message2
$("body, html").animate({
scrollTop: $($("#message")).offset().top - 5000
}, 600);
}
});
return false;
});
在我想指明返回DIV是,像
<form action="../forms/add_event_form.php" method="post" id="ajaxForm">
//Can I add an input somewhere here? To indicate where I want the return to go too? Like <input type="hidden" value="message2" name="return">
<input type="text" class="formI" name="date" id="dateI" placeholder="Date">
<input type="submit" name="submit" class="btn btn-primary" value="Add">
</form>
感謝您閱讀此形式。祝你有美好的一天!並且預先感謝您的回覆。