我将在ajax中给出参数get?

时间:2013-03-25 06:44:33

标签: asp.net-mvc-3 jquery

这是我的控制器动作,返回json

public ActionResult MapTest(string date)
        {
            var locations = _db.EMP_LOCATION.Where(m => m.CURRENT_DATE.Equals(date));
            return Json(locations,JsonRequestBehavior.AllowGet);
        }

我的脚本在这里

var script = {
    callAction: function () {

        $.ajax({
            url: 'Home/MapTest',
            type:'GET',
            dataType: "json",
            success: function (message) {
                var count = message.length;
                for (var i = 0; i < count; i++) {
                    $('#maplong').append(message[i].LATITUDE, "  ", message[i].LONGITUDE," ");
                }
            },
            complete: function () {
                alert('completed');
            }
        });
    }
}

现在我的问题是我可以在$ .ajax中给出日期参数以及如何?

3 个答案:

答案 0 :(得分:0)

做一些像:

var script = {
    callAction: function () {

        $.ajax({
            url: 'Home/MapTest',
            type:'GET',
            data: JSON.stringify({ date: "your date" })
            dataType: "json",
            success: function (message) {
                var count = message.length;
                for (var i = 0; i < count; i++) {
                    $('#maplong').append(message[i].LATITUDE, "  ", message[i].LONGITUDE," ");
                }
            },
            complete: function () {
                alert('completed');
            }
        });
    }
}

最好的问候

答案 1 :(得分:0)

您可以在URL中传递值,如下所示:

var script = {
    callAction: function () {
     var dateVal= "Your date";
        $.ajax({
            url: 'Home/MapTest?date='+dateVal,
            type:'GET',               
            dataType: "json",
            success: function (message) {
                var count = message.length;
                for (var i = 0; i < count; i++) {
                    $('#maplong').append(message[i].LATITUDE, "  ", message[i].LONGITUDE," ");
                }
            },
            complete: function () {
                alert('completed');
            }
        });
    }
}

答案 2 :(得分:0)

var script = {     callAction:function(){

    $.ajax({
        url: 'Home/MapTest',
        type:'GET',
        dataType: "html",
        data: { date : "03/25/2013" },
        success: function (message) {
            var count = message.length;
            for (var i = 0; i < count; i++) {
                $('#maplong').append(message[i].LATITUDE, "  ", message[i].LONGITUDE," ");
            }
        },
        complete: function () {
            alert('completed');
        }
    });
}

}