1

I want to call the static method which is in server side by AJAX function which is in client side in asp.net. I have seen in debug mode also, but not getting in that method while there is no error also showing in windows console and for refer Google also the syntax also right. Then not getting me that why static method is not called by AJAX method.

Here is my code. This is client side code

<input type="submit" id="submit_mail" value="Send" />

<script>
   $(function () {
      $.ajax({
             type: "POST",
             url: "contact.aspx/SendMail",
             data: JSON.stringify({ name: $('#txt_name').val(), email: $('#txt_emailID').val(), subject: $('#txt_subject').val(), message: $('#txt_content').val() }),
             success: OnSuccess,
             failure: function () {
                      alert("There is some problem in server to contact with us....Please contact with phone number...!!!");
                        }
                  });
            });
           function OnSuccess() {
                   $find("mpe").show();
                        return false;
          }    
</script>

This is the server side call

[WebMethod]
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static void SendMail(string name, string email, string subject, string message)
{
 //here is the code
}

Now the issues is that only that after AJAX call this static method is not fired.

halfer
  • 19,824
  • 17
  • 99
  • 186
s.k.Soni
  • 1,139
  • 1
  • 19
  • 37
  • Try using these in your AJAX call. contentType: "application/json;charset=utf-8", dataType: "json", – The_Outsider Jul 03 '17 at 18:08
  • Possible duplicate of [How to send and retrieve data from web method using JQuery Ajax Call?](https://stackoverflow.com/questions/17655807/how-to-send-and-retrieve-data-from-web-method-using-jquery-ajax-call) – Ziv Weissman Jul 03 '17 at 18:08
  • you do not need JSON.stringify – Soheil Alizadeh Jul 03 '17 at 18:08
  • @The_Outsider ....this thing I done but then also same issue is coming – s.k.Soni Jul 03 '17 at 18:14
  • 1
    You should add [HttpPost] onto your action and I would suggest to create one more action which will get post request then you can call mail action in extra action you created – hasan Jul 03 '17 at 18:16

0 Answers0