The following method works:

[System.Web.Services.WebMethod]
public string GetData(string year)
{
    Int32 iYear = DateTime.Now.Year;
    if (DateTime.IsLeapYear(iYear))
    {
        return "true";
    } else
    {
        return "false";
    }
}

But if I pass a year say 2015 as a string, the following code doesn't work.

using System;

public partial class _Default : System.Web.UI.Page
{
public string output = "";
protected void Page_Load(object sender, EventArgs e)
{
    if (Request.Params["callback"] != null)
    {
        output = Request.Params["callback"] + "('" + GetData(Request.Params["year"]) + "')";
    }
}

[System.Web.Services.WebMethod]
public string GetData(string year)
{
    int iYear = Convert.ToInt32(year);

    if (DateTime.IsLeapYear(iYear))
    {
        return "true";
    } else {
        return "false";
    }
}
}

I'm having a hard time figuring out my mistake. I'm passing year as a string to an jQuery Ajax call.

Any ideas why?

Joe

Related posts

Recent Viewed