У меня возникла проблема с получением метода AJAX в JQUERY для публикации на моем классическом ASP-странице метода отправки электронной почты. Вот мой код. Скажите, пожалуйста, какую ошибку я делаю. Также предложите мне перенаправить на предыдущую страницу html после выполнения моей функции ap-страницы.
function QuickEmail() {
$.ajax({
type: "POST",
url: "emailsending.asp",
data: '{FirstName: "' + $("#txtFirstName").val() + '",LastName:"' +
$("#txtLastName").val() + '",Email:"'
+ $("#txtEmail").val() + '",ContactNo:"' + $("#txtContactNo").val() + '"}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
}
});
$.unblockUI();
}
function OnSuccess(response) {
$.msgBox({ title: "Message Sent!", content: "Message has been sent successfully.", type: "info" });
}
Вот моя страница ASP
enter code here
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
</head>
<body>
<%
dim FirstName
dim LastName
dim EmailAdd
dim Contact
FirstName = Request("txtFirstName")
LastName = Request("txtLastName")
EmailAdd = Request("txtEmail")
Contact = Request("txtContactNo")
Set Mail = CreateObject("CDO.Message")
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") ="smtp.gmail.com"
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") ="[email protected]" 'You can also use you email address that setup through google apps.
Mail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") ="xxxxxxxx"
Mail.Configuration.Fields.Update
Mail.Subject= FirstName
Mail.From= "[email protected]"
Mail.To=EmailAdd
Mail.TextBody=FirstName & vbCrLf & LastName & vbCrLf & Contact & vbCrLf & EmailAdd
Mail.Send
Set Mail = Nothing
Response.Redirect("index.html")
%>
</body>
</html>
Вы передаете свои данные таким образом:
data: '{FirstName: "' + $("#txtFirstName").val()
+ '",LastName:"' + $("#txtLastName").val()
+ '",Email:"' + $("#txtEmail").val()
+ '",ContactNo:"' + $("#txtContactNo").val() + '"}',
когда вы теперь получаете доступ к данным с идентификаторами формы, вы получите, возможно, неверные или null
данные.
Вместо этого попробуйте либо:
отправьте свою форму вместо ручного анализа JSON-Data: это будет выглядеть так
data: document.forms.quickmail.data,