gpt4 book ai didi

javascript - 如何在javascript函数中接收ajax调用的POST数据

转载 作者:行者123 更新时间:2023-11-28 11:02:27 26 4
gpt4 key购买 nike

我需要一点帮助。我正在尝试使用 ajax 分页实现 Bootstrap 数据表。由于这是移动应用程序(Cordova),我也完全依赖服务器端的 javascript。这就是为什么我在 url 中调用 javascript 函数。现在我不知道如何获取其中的 POST 数据。任何帮助将不胜感激。

$(document).ready(function(){
$("‪#‎products‬").dataTable({
aLengthMenu: [
[10, 25, 50, 100, -1], [10, 25, 50, 100, "All"]
],
aaSorting: [],
bProcessing: true,
serverSide: true,
ajax:{
url : ProductList.getProductsPaginated(),
type: "post", // type of method , by default would be get
error: function(){ // error handling code
}
}
});

ProductList.getProductsPaginated(){
// This method gets called succesfully
// Need the post data here
}
});

编辑:让我们不使用函数作为 url 参数,直接使用 html 页面,如

url : "page.html",

现在,如何获取html或js中的post数据?对于我正在寻找的东西还有其他方法吗?

最佳答案

我不明白为什么你需要该函数内的数据,但它不会在ajax成功时被调用,它是因为括号而被调用的,我认为你唯一能做的就是返回你的 json 数据,但是你可以使用 ajax 成功时的发布数据调用一个函数,如下所示:

ajax: {
url : ProductList.getProductsPaginated(),
type: "post",
dataSrc: function (data) {
// you can call a function here with the data as parameter
// you have to return the data, with modifications if you need
return data;
}
}

关于javascript - 如何在javascript函数中接收ajax调用的POST数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34229274/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com