Cannot access C # method using jquery

I am trying to call a C # method from a java script, I am new to web development, and after a bit of searching based on using jquery to do the same, the way I am trying to call a method:

$.ajax({
          type: "POST",
          url: "Default.aspx/IncrementJ",
          data: "{}",
          contentType: "application/json; charset=utf-8",
          dataType: "json",
          success: function(msg) {
            alert("success!")
          }
        });

here IncrementJ is my function name, defined in C #, which I want to call. Here is the definition:

 [WebMethod]
    public static  void IncrementJ()
    {

        try
        {
            j++;
        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

when I run my program, the web console gives an error message "cannot find incrementJ resource", tell me where I am mistaken,

Thank.

+3
source share
2 answers

Given your comments that the error state is 404 (not found), we can conclude that the error is on behalf of the calling script:

"Http Answer Codes for Dummies"

50x: we messed up. 
40x: you messed up. 
30x: ask that dude over there. 
20x: cool.

, , script -, , , . Default.aspx/IncrementJ.

+4

, , - . JS, {} not "{}"

+1

All Articles