Sunday, April 19, 2015

ajax call using jquery in asp.net

Event:

 <a class="btnTwo btnTwoOrange btnSelectSend" href="JavaScript:" id="btnSelectSend" onclick="SendEmail();">Gönder</a>  

Javascript:

  <script type="text/javascript">  
       function SendEmail() {  
         var bookId = document.getElementById("BookID").value;  
         var name = document.getElementById("sendername").value;  
         var email = document.getElementById("senderEmail").value;  
         $.ajax({  
           type: "POST",  
           url: "Forbes.aspx/SendEmail",  
           data: "{ bookId: '" + bookId + "',name: '" + name + "',email: '" + email + "'}",  
           contentType: "application/json; charset=utf-8",  
           dataType: "json",  
           async: "true",  
           cache: "false",  
           success: function (msg) {  
            // do something            
           },  
           Error: function (x, e) {  
             // On Error  
           }  
         });  
       }  
     </script>  


In to CS file:


   [WebMethod]  
     public static void SendEmail(string bookId, string name, string email)  
     {  
       try  
       {  
         MemberService.SendForbesEmail(bookId, name, email, db, m_Member);  
       }  
       catch (Exception ex)  
       {  
         throw;  
       }  
     }   


Hope it will help you.




Ensure that this project has Microsoft.Bcl.Build installed and packages.config is located next to the project file

In my Xamarin form application their was dependency Restclient on Microsoft.Bcl.Build Microsoft.Bcl. i just remove all using nuget and ...