---
title: "jquery databtable editable 如何切换ajax Source"
author: "chainhou"
date: "2012-02-17T11:30:34Z"
tags: []
categories: ["Web前端"]
slug: "jquery-databtable-editable-ajax-source"
draft: false
lastmod: "2012-02-17T11:30:34Z"
id: 1409323
url: "https://chainhou.iteye.com/blog/1409323"
---

:D 

"fnServerData": function ( sSource, aoData, fnCallback ) {
    aoData.push( { "name": "table", "value": "wordforms" } );
        $.ajax( {
            "dataType": 'json', 
            "url": sSource, 
            "data": aoData, 
            "success": fnCallback
            } );
}


"fnServerData": function ( sSource, aoData, fnCallback ) {
			/* Add some extra data to the sender */
			aoData.push( { "name": "more_data", "value": "my_value" } );
			$.getJSON( sSource, aoData, function (json) { 
				/* Do whatever additional processing you want on the callback, then tell DataTables */
				fnCallback(json)
			} );
		}



ReloadAjax, same source URL, different POST parameters
对于仅使用jq.datatable version >1.8.2 及jq.jeditable ，可以使用fnReloadAjax(url?param=newValue)
对于使用jq.datatable.editable的，因为这个插件是用的jq.datatable version 1.7.5,所以有许多新版功能还没有实现。所以要实现更改ajax source的参数，就需要用到
"fnServerData": function ( sSource, aoData, fnCallback ) {
    aoData.push( { "name": "table", "value": param } );
        $.ajax( {
            "dataType": 'json', 
            "url": sSource, 
            "data": aoData, 
            "success": fnCallback
            } );
}
在外部的button或者select里更改param的值后调用oTable.fnDraw();
在服务器端要得到参数，只需要getParam("table");   参数名字就是在aoData里name的值。