我有AJAX请求
这是代码
<script>
$(document).ready(function () {
$('#save').click(function () {
send_email();
});
});
function send_email() {
$.ajax({
url: '/Questions/SendEmail',
dataType: "json",
type: "GET",
contentType: 'application/json; charset=utf-8',
async: false,
processData: false,
cache: false,
delay: 15,
success: function (result) {
alert("Email Forwarded")
},
error: function (xhr) {
alert('error');
}
});
}
</script>
这是后端代码
public JsonResult SendEmail() {
SmartSolutions.Models.InvitationMail _objModelMail = new SmartSolutions.Models.InvitationMail();
var emailList = db.InvitationMails.Select(model => model.To);
var emailList2 = db.InvitationMails.Select(model => model.Link);
var link2 = emailList2.FirstOrDefault();
var emails = String.Join(",", emailList);
MailMessage mail = new MailMessage();
mail.To.Add(emails);
mail.From = new MailAddress(_objModelMail.From = "suhomlin.eugene93@gmail.com");
mail.Subject = _objModelMail.Subject = "Видео интервью";
string Body = _objModelMail.Body = "Предлагаем пройти интервью" + link2;
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.UseDefaultCredentials = false;
smtp.Credentials = new System.Net.NetworkCredential
("***********", "*********");// Enter seders User name and password
smtp.EnableSsl = true;
smtp.Send(mail);
return Json(new { Result = "Success", Message = "Saved Successfully",JsonRequestBehavior.AllowGet});
}
但是当我启动AJAX请求时,我收到此错误
此请求已被阻止,因为敏感信息可能会泄露给第三方网站
我如何解决?
答案 0 :(得分:3)
更改强>
return Json(new { Result = "Success", Message = "Saved Successfully",JsonRequestBehavior.AllowGet});
要强>
return Json(new { Result = "Success", Message = "Saved Successfully"},JsonRequestBehavior.AllowGet);