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 に答える