2011-02-02 81 views

回答

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; 
} 

然後在服務器端:

箱子一個新的處理程序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); 

    } 
+0

威爾仍然打`保護無效Submit_Click(對象發件人,EventArgs e)在代碼後面發送表單? – balexander 2011-02-02 02:16:16