Tanmay Nehete
Tanmay Nehete

Reputation: 2198

Jquery ajax call is not working when changing the framework from 3.5 to 4.0

tested with alert.. but ajax call is not working and my aspx.cs when i change my .net framework from 3.5 to 4.0

my ajax funcation

function GetCustomers(pageIndex) {
            $.ajax({
                type: "POST",
                url: "Webusers.aspx/GetCustomers",
                data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: OnSuccess,
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
        }

and my .cs method

 [WebMethod(EnableSession = true)]


 public static string GetCustomers(string searchTerm, int pageIndex)
    {

        string query = "SearchWebUserData";
        if (!string.IsNullOrEmpty(HttpContext.Current.Request.Form["gender"]))
        {
            string sSeraachType = HttpContext.Current.Request.Form["gender"];
        }
        SqlCommand cmd = new SqlCommand(query);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@SearchTerm", searchTerm);
        cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
        cmd.Parameters.AddWithValue("@PageSize", PageSize);
        cmd.Parameters.AddWithValue("@flag", "E");
        cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
        return GetData(cmd, pageIndex).GetXml();
    }

Upvotes: 0

Views: 704

Answers (1)

Mandar Dhadve
Mandar Dhadve

Reputation: 381

First of all make sure you've valid handler mappings in web.config as shown below:

<system.web>
  <httpHandlers>
    <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
  </httpHandlers>
</system.web>

Just pass jQuery an object and it will stringify it for you:

  data: { 'searchTerm':"'+ SearchTerm()+'", 'pageIndex': "'+pageIndex+'" }

Upvotes: 1

Related Questions