0

I am using jquery ajax call in asp.net,I have a static web method with some parameters, When I am trying to debug its not hitting the method, I saw in error log its showing parseError, I removed all parameters and checked,but still same error,

[WebMethod]
  private static void AddData(int type, int categ, string desc, string date, string city, string state)

        {
//Do Processing
        }

I also tried with this,but same error

[WebMethod]
        private static void AddData()
        {
//do Processing
        }

This is my ajax call

 $.ajax({
                type: "POST",
              url: 'MyPage.aspx/AddData?type=' + encodeURIComponent(crimetype) + "&categ=" + encodeURIComponent(crimecateg) + "&desc=" + encodeURIComponent(desc) + "&date=" + encodeURIComponent(crimedate) + "&city=" + encodeURI(city) + "&state=" + encodeURIComponent(stateid),

                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                },
                error: function (data, errorThrown) {
                    debugger
                    alert(errorThrown);
                    alert(data.toString());
                }
            });

I tried with this as well

$.ajax({
                type: "POST",
                url: 'MyPage.aspx/AddData',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                },
                error: function (data, errorThrown) {
                    debugger
                    alert(errorThrown);
                    alert(data.toString());
                }
            });

All parameters are passing correctly

1
  • does putting the URL in " " instead of ' ' change anything? Commented Feb 24, 2014 at 11:03

3 Answers 3

1

Change the Access Modifier

private static void AddData()

to

public static void AddData()
Sign up to request clarification or add additional context in comments.

5 Comments

its not hitting when I am debugging the method
u mean the c# method? And where r u calling the ajax call?
yes its C# web method and I am calling it in asp.net page
i mean where r u calling the ajax call..in document ready or on click of some button.Can u show dat code
its in a function whhich is outside document.ready, and I am calling it inside document.ready
0

All parameters going to json data like so:

var jsonData = {
    categ: value,
    desc: value,
    // and others
}

$.ajax({
                type: "POST",
                url: 'MyPage.aspx/AddData'
                data: jsonData //your parameters
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (data) {
                },
                error: function (data, errorThrown) {
                    debugger
                    alert(errorThrown);
                    alert(data.toString());
                }
            });

3 Comments

Could you elaborate this answer? What changes did you make and what are the effects?
its not hitting the method when I am debugging the method
you forget data property in $.ajax function, this property is include all ur url parameters
0

Try this.

[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public static void AddData()
{
   //Your logic
}

And during call

$(document).ready(function () {
            InsertData();
        });
        function InsertData() {
            $.ajax({

                type: "POST",

                contentType: "application/json; charset=utf-8",

                url: "MyPage.aspx/AddData",

                data: "{}",

                dataType: "json",
                success: function (response) {}
                error: function (data, errorThrown) {
                    debugger
                    alert(errorThrown);
                    alert(data.toString());
                }
            });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.