With Ajax and JS/Jquery I'm trying to send a simple Contact form to a Classic ASP (aspemail) and sent a messagem from a page without reload.
使用Ajax和JS / Jquery我正在尝试将一个简单的Contact表单发送到Classic ASP(aspemail)并从页面发送messagem而不重新加载。
<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>
My ASPEMAIL.ASP is only test asp and I write only:
我的ASPEMAIL.ASP只是测试asp而且我只写:
<%
Response.Write("ok")
%>
And my JQuery Script:
我的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>
I put a redirect on success to test (My objective is a message only) - but nothing happens.
我对成功进行了重定向测试(我的目标只是一条消息) - 但没有任何反应。
But after send the "LOADING" appears on screen and hide and then the submit and "complete" is working.
但发送后,“加载”出现在屏幕上并隐藏然后提交和“完成”正在工作。
Any idea what is wrong?
知道什么是错的吗?
1 个解决方案
#1
0
you have 2 variables named data, try using a different variable here, as I believe you're "confusing" javascript here :)
你有2个变量名为data,尝试在这里使用不同的变量,因为我相信你在这里“混淆”javascript :)
success: function(dataReturned) {
if(dataReturned === "ok")
{
document.location = "final.asp";
}
},
#1
0
you have 2 variables named data, try using a different variable here, as I believe you're "confusing" javascript here :)
你有2个变量名为data,尝试在这里使用不同的变量,因为我相信你在这里“混淆”javascript :)
success: function(dataReturned) {
if(dataReturned === "ok")
{
document.location = "final.asp";
}
},