[英]Pass Parameters through ajax call - ajax url
I am trying to pass value parameter through the ajax call to the controller. It is a date value.我正在尝试通过 ajax 调用将值参数传递给 controller。它是一个日期值。 I am struggling to find a way to pass parameters through this ajax url. Please help.
我正在努力寻找一种方法来通过这个 ajax url 传递参数。请帮助。
function dataTable() {
var value = $("#somedatevalue).val();
$("#thisTable").DataTable({
"processing": true,
"paging": false,
"language": {
processing: "<span class='processing-message'><i class='fa fa-circle-o-notch fa-spin'></i> Processing...</span>"
},
ajax: {
url: $('table#thisTable').data("ajaxurl"),
type: "POST",
datatype: "json",
},
"columns": [
{
"data": "column1",
},
{
"data": "column2",
},
{
"data": "column3",
},
{
"data": "column4",
},
{
"data": "column5",
},
{
"data": "Url",
"render": function (data) {
return '<a class="btn btn-info" href="' + data + '">Select</a>';
}
}
],
"dom": 't<"col-lg-3"l><"col-lg-6"p><"col-lg-3"i>'
});
}
You can pass value as query parameter like http://www.url.com?date="17-02-21"
您可以将值作为查询参数传递,例如
http://www.url.com?date="17-02-21"
If you are using php use can get the value as
$_GET['date']
If you are using node.js, you can get value asreq.query.date
如果您使用的是 php,则可以使用
$_GET['date']
获取值 如果您使用的是 node.js,则可以获取值为req.query.date
Consider the following.考虑以下。
function dataTable() {
$("#thisTable").DataTable({
"processing": true,
"paging": false,
"language": {
processing: "<span class='processing-message'><i class='fa fa-circle-o-notch fa-spin'></i> Processing...</span>"
},
"ajax": {
"url": $('table#thisTable').data("ajaxurl"),
"type": "POST",
"data": { "someDate": $("#somedatevalue").val() },
"datatype": "json"
},
"columns": [
{
"data": "column1",
},
{
"data": "column2",
},
{
"data": "column3",
},
{
"data": "column4",
},
{
"data": "column5",
},
{
"data": "Url",
"render": function (data) {
return '<a class="btn btn-info" href="' + data + '">Select</a>';
}
}
],
"dom": 't<"col-lg-3"l><"col-lg-6"p><"col-lg-3"i>'
});
}
First you must address the Typo in your jQuery Selector.首先,您必须解决 jQuery 选择器中的拼写错误。 Then you can adjust your Ajax parameters to include a
data
.然后你可以调整你的 Ajax 参数来包含一个
data
。
See more here: https://datatables.net/reference/option/ajax.data在此处查看更多信息: https://datatables.net/reference/option/ajax.data
In principle it operates in exactly the same way as jQuery's
$.ajax.data
property, in that it can be given as an object with parameters and values to submit, but DataTables extends this by also providing it with the ability to be a function, to allow the data to be re-evaluated upon each Ajax request (see above).原则上它的操作方式与 jQuery 的
$.ajax.data
属性完全相同,因为它可以作为 object 给出,并带有要提交的参数和值,但 DataTables 扩展了它,还为其提供了成为 function 的能力,允许根据每个 Ajax 请求重新评估数据(见上文)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.