0

这是我返回 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 中的日期参数以及如何?

4

3 回答 3

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');
            }
        });
    }
}

此致

于 2013-03-25T06:48:23.047 回答
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');
            }
        });
    }
}
于 2013-03-25T06:51:36.387 回答
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');
        }
    });
}

}

于 2013-03-25T17:04:41.273 回答