1

I an sendig json object strid as follows:

var strid = "{id:'"+val.id+"'}";
        $.ajax({
            type: "POST",
            url: "FrmUserPortal.aspx/AnnounceInfo",
            data:JSON.stringify(strid), 
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data) {

                var mydata = data.d;
                alert(mydata);

            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                alert("Request: " + XMLHttpRequest.toString() + "\n\nStatus: " + textStatus + "\n\nError: " + errorThrown);
            },
        });

but the webmethod is not calling . my method is

    [WebMethod]
    [ScriptMethod(UseHttpGet = false)]
    public static Announce AnnounceInfo(string Id)
    {
       string dgFill = "Select AnnounceTitle,AnnounceDescription  From AnnouncementInformation  Where AnnouncetId = '"+Id+"'";
       DataTable dtFill = DataManager.ExecuteQuery(dgFill);

       Announce An = new Announce();
       if (dtFill.Rows.Count > 0)
        {

            An.AnnounceTitle = dtFill.Rows[0]["AnnounceTitle"].ToString();
            An.AnnounceDescription=dtFill.Rows[0]["AnnounceDescription"].ToString();

            return An;
        }

       return An;

    }
public class Announce
    {
        public string AnnounceTitle { get;set;}
        public string AnnounceDescription { get; set; }

    }
Giannis Paraskevopoulos
  • 18,261
  • 1
  • 49
  • 69
Belayet
  • 55
  • 1
  • 10

2 Answers2

0

You use Json.stringify, but you send a string as parameter. Try creating the object like this:

var strid = {"Id": val.id };
Cosmin Vană
  • 1,562
  • 12
  • 28
0

Can you please refer this link:
Web method is not called by jquery from javascript function?

I hope it will help and try to return a JSON object.

Community
  • 1
  • 1
Mukund
  • 1,679
  • 1
  • 11
  • 20