Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6062811
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:05:39+00:00 2026-05-23T09:05:39+00:00

I am calling a ajax method as below var srchText = Chicago; $.ajax({ url:

  • 0

I am calling a ajax method as below

 var srchText = "Chicago";


 $.ajax({
    url: "/Ajax/GetCities",
    data: "{'srchText' : '" + srchText + "'}",
    dataType: "json",
    type: "POST",
    async: false,
    contentType: "application/json; charset=utf-8",
    dataFilter: function (data) { return data; },
    success: function (data) {
        cityList = data.d;
    }
});

The url is pointing to a MVC controller, as below,

 [HttpPost]
    public ActionResult GetCities(string srchText)
    {
        List<City> result = new List<City>();
        EventsBIZ objBIZ = new EventsBIZ();
        result = objBIZ.ToList<City>(objBIZ.GetCities(srchText));
        return this.Json(new GetEventsResponse() { d = result }, JsonRequestBehavior.AllowGet);
    }

There is something wrong with the code, that the method is called successfully, but the srchText is coming as null. Please help me to figure out wat went wrong. Thanks in advance

Adding the request tracked from firebug.
FireBug Net monitor

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:05:40+00:00Added an answer on May 23, 2026 at 9:05 am

    The reason your code doesn’t work is because by default ASP.NET MVC 2 doesn’t understand JSON requests. There is nothing built-in that allows you to send a JSON formatted request and that this request is parsed back to a strongly typed action argument. This functionality is built-in by default starting from ASP.NET MVC 3. Take a look at the following blog post. You will need to implement a JsonValueProviderFactory if you want to make this work under ASP.NET MVC 2.

    Also instead of:

    data: "{'srchText' : '" + srchText + "'}",
    

    you should use:

    data: JSON.stringify({ srchText: srchText }),
    

    The JSON.stringify is native for modern browsers, and for older you might need to include json2.js.

    Another possibility if you don’t want to implement a JsonValueProviderFactory is to use a standard application/x-www-form-urlencoded request which the default model binder can understand:

    $.ajax({
        url: '/Ajax/GetCities',
        data: { srchText: srchText },
        type: 'POST',
        async: false,
        dataType: 'json',
        dataFilter: function (data) { return data; },
        success: function (data) {
            cityList = data.d;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am calling a service that return JSON data. Script: $.ajax({ type: "POST", url:
i call my asp.net page method like below code $.ajax({ type: POST, url: MyPage.aspx/GetItems,
At the moment I'm using the post method like this $.ajax({ type: POST, url:
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
I'm calling a web service using jquery's ajax method and it seems to work
I am calling an ASP.NET Ajax method (e.g. a method tagged with [Ajax.AjaxMethod] )
I'm calling ajax.php with jQuery. It returns a JSON response all the time. $.ajax({
I am using the ajax post method to send values from aspx to php.in
I am calling a WCF Service using AJAX.NET and wanted to know if the
I am calling a .txt file from a jquery ajax call. It has some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.