Send string parameter to controller using AJAX call for jquery

jquery

Solution

You need to define name for the data you sending `data: {'status': status}`:

this.GetTransactionsInputToday = function () {
    var status="complete"
    var r = '';

    $.ajax({
        url: '/Management/function1',
        contentType: "application/json; charset=utf-8",
        data: {'status': status},
        type: 'GET',
        cache: false,
        success: function (result) {
            r = result;
        }
    });

    return r;
};

Also your `this.GetTransactionsInputToday` will not return result as you expected. The success handler of ajax function gets called asynchronously. So your `return r` statement will return '' as it gets called before the Ajax request gets completed.

Problem

I have a ajax call that goes like ``` this.GetTransactionsInputToday = function () { var status="complete" $.ajax({ url: '/Management/function1', contentType: "application/json; charset=utf-8", data: status, type: 'GET', cache: false, success: function (result) { return result; } }); } ``` I have also tried doing like this ``` this.GetTransactionsInputToday = function () { var status="complete"; $.ajax({ url: '/Management/function1/' + status, type: 'GET', cache: false, success: function (result) { return result; } }); } ``` I have a controller function in my management controller class ``` public JsonResult function1(string status) { Some code here.. } ``` The issue is that every time function1 is called teh value of status comes as null. CAn any one please let me know where am I going wrong??

Original source