目前,我有一个小型表单,使用asp:linkbutton
提交并发送电子邮件。
当用户点击表单而不是完整的回帖时,我想显示一个灯箱,上面写着“感谢您的提交”。
什么是最佳解决方案?
答案 0 :(得分:2)
您需要截取事件以阻止表单发布,然后调用您的灯箱。像这样:
$('#yourbutton').bind('click', function() {
event.preventDefault();
//do an asynchronous post here
$.ajax({
type: 'POST',
url: 'http://yoursite.com/yourhandler.ashx',
data: {param1:value1,param2:value2}, //if needed
success: function(data) {
//here you check for the data returned to be valid, not required
$('#yourDiv').show(); //show a div here or you can just show a lightbox
},
dataType: 'json'
});
return false;
}
然后在服务器端:
创建一个新的Handler myHandler.ashx,如下所示:
public class myHandler : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
//this is not required if you are not passing any parameters
string param1 = context.Request["param1"].ToString();
string param2 = context.Request["param2"].ToString();
string output = "";
//here you would insert your function that would send the email or whatever it is that your function does.
//set the output
output = "{Success:true"}";
context.Response.Write(output);
}