【发布时间】:2016-08-03 02:40:02
【问题描述】:
使用 Ajax 和 JS/Jquery 我正在尝试将简单的联系表单发送到经典 ASP (aspemail) 并从页面发送消息无需重新加载。
<form id="form-submit" action="ASPEmail.asp" method="post">
Name<br>
<input id="name" type="text"><br>
E-mail<br>
<input id="email" type="text"><br>
Message:<br>
<textarea id="msg"></textarea><br>
<input type="submit" id="btn" value="SEND">
<img src="loading.gif" class="loading">
</form>
我的 ASPEMAIL.ASP 只是测试 asp,我只写:
<%
Response.Write("ok")
%>
还有我的 JQuery 脚本:
<script src="https://code.jquery.com/jquery-3.1.0.js"></script>
<script>
$(function() {
$("#form-submit").submit(function() {
var data = $(this).serialize(),
action = $(this).attr("action"),
method = $(this).attr("method");
$(".loading").show(); // show loading div
$.ajax({
url: action,
type: method,
data: data,
success: function(data) {
if(data === "ok")
{
document.location = "final.asp";
}
},
error: function(err) {
// there was something not right...
},
complete: function() {
$(".loading").hide(); // hide the loading
}
});
return false; // don't let the form be submitted
});
});
</script>
我对成功进行了重定向以进行测试(我的目标只是一条消息)-但没有任何反应。
但发送后“加载”出现在屏幕上并隐藏,然后提交和“完成”工作。
知道有什么问题吗?
【问题讨论】:
-
data在控制台登录时返回什么? (在succes: function(data) {},if函数之前? -
Check the browser console 看看到底发生了什么;特别是网络标签。
标签: javascript jquery ajax asp-classic