将数据添加到.Ajax数据+额外数据 [英] Add Data to .Ajax data + extra data
本文介绍了将数据添加到.Ajax数据+额外数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,我希望能够向在Ajax上提交的数据中添加其他数据:
Hello I want to be able to add additional data to my data being submitted on 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 ...请帮助!
However I get a script error and it won't send it to my URL... Please help!
我现在正在传递它,就像这个DPID碰巧,但dt却没有:
I am now passing it like this DPID comes across fine but dt does not:
<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>
推荐答案
如果要向ajax请求中添加一些其他数据,请使用以下方法:
if you want to add some additional data to the ajax request, use this:
"fnServerParams": function ( aoData ) {
aoData.push( { "key": "value" } );
}
这篇关于将数据添加到.Ajax数据+额外数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文