将数据添加到.Ajax数据+额外数据

编程入门 行业动态 更新时间:2024-10-22 13:45:03
本文介绍了将数据添加到.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() { //www.datatables $('#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() { //www.datatables $('#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数据+额外数据

本文发布于:2023-11-27 08:11:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637225.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据   Ajax

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!