加入收藏 | 设为首页 | 会员中心 | 我要投稿 南京站长网 (https://www.025zz.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

无法使用ajax将多维数组传递给php

发布时间:2022-11-19 14:30:39 所属栏目:PHP教程 来源:转载
导读: Array I am trying to pass: 我想通过的数组:
var params = [];
params['request'] = "movies";
params['param'] = [];
params['param']['sortBy'] = "title";
params['param'][�

Array I am trying to pass: 我想通过的数组:

var params = [];
params['request'] = "movies";
params['param'] = [];
params['param']['sortBy'] = "title";
params['param']['sortOrder'] = "asc";

Ajax call: Ajax呼叫:

return $.ajax({
        type: "POST",
        url: "http://192.168.0.100:83/getData.php",
        cache:false,
        data: params,
        dataType:"json",
        success: function(data){
            if(data != null){
                            console.log(data);
                        }

Problem is that the php script only receives $_POST['request'], params is non-existent. 问题是php脚本仅接收$ _POST ['request'],参数不存在。

If I view params array in the console log before the ajax call I see this: 如果我在ajax调用之前在控制台日志中查看params数组,则会看到以下内容:

[request: "movies", param: Array[0]]
length: 0
param: Array[0]
length: 0
sortBy: "title"
sortOrder: "asc"
__proto__: Array[0]
request: "movies"
__proto__: Array[0]

It seems like the problem could be that "param" parameter is not passed because it is seen as empty (it is not, at least before it is passed to ajax call), but why this is happening I have no idea. 似乎问题可能在于未传递“ param”参数PHP多维数组,因为它被视为空(至少在传递给ajax调用之前,它不是),但是为什么这种情况我不知道。 What am I missing here? 我在这里想念什么?

(编辑:南京站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!