1

こんにちは、Ajaxで送信されるデータにデータを追加できるようにしたいと思います。

<script type="text/javascript">
$(document).ready(function() {
    //http://www.datatables.net
$('#dataTable').dataTable({
        "sPaginationType": "full_numbers",
        "bJQueryUI": false,
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "/Project/GetDataTables2",
        "aoColumns": [
            { "bSortable": true },
            { "bSortable": true },
            { "bSortable": true },
            { "bSortable": true }
        ],
        "fnServerData": function(url, data, callback) {
            $.ajax({
                "url": url,
                "data": data, //I want to add additional data from here like the QueryString DPID
                "success": callback,
                "contentType": "application/x-www-form-urlencoded; charset=utf-8",
                "dataType": "json",
                "type": "POST",
                "cache": false,
                "error": function() {
                    alert("DataTables warning: JSON data from server failed to load or be parsed. " +
                    "This is most likely to be caused by a JSON formatting error.");
                }
            });
        }
    });
});                    
</script>

私はやってみました:

data: data + "&moredata=" + morevalue 

ただし、スクリプトエラーが発生し、URLに送信されません...助けてください!

編集1:

私は今、このDPIDがうまくいくようにそれを渡しますが、dtはそうではありません:

<script type="text/javascript">
$(document).ready(function() {
    //http://www.datatables.net
    $('#dataTable').dataTable({
        "sPaginationType": "full_numbers",
        "bJQueryUI": false,
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "/Project/GetDataTables2",
        "aoColumns": [
            { "bSortable": true },
            { "bSortable": true },
            { "bSortable": true },
            { "bSortable": true }
        ],
        "fnServerData": function(url, data, callback) {
            $.ajax({
                "url": url,
                "data": { DPID: "1", dt: data }, //I want to add additional data from here like the QueryString DPID
                "success": callback,
                "contentType": "application/x-www-form-urlencoded; charset=utf-8",
                "dataType": "json",
                "type": "POST",
                "cache": false,
                "error": function() {
                    alert("DataTables warning: JSON data from server failed to load or be parsed. " +
                    "This is most likely to be caused by a JSON formatting error.");
                }
            });
        }
    });
});                    
</script>
4

3 に答える 3

0

データはオブジェクトなので、次のことができます。

data.moredata=morevalue

成功ハンドラー内でそれを行うか、必要に応じてパラメーターとしてデータを渡す必要があります

編集1:

あなたの情報を見たので、これを試してください:

"fnServerData": function(url, data, callback) {
           data={ DPID: "1", dt: data } 
           $.ajax({
                "url": url,
                "data": data, //I want to add additional data from here like the QueryString DPID
                "success": callback,
                "contentType": "application/x-www-form-urlencoded; charset=utf-8",
                "dataType": "json",
                "type": "POST",
                "cache": false,
                "error": function() {
                    alert("DataTables warning: JSON data from server failed to load or be parsed. " +
                    "This is most likely to be caused by a JSON formatting error.");
                }
            });
        }
于 2012-10-22T22:08:45.293 に答える