Javascript数组未完全分配给php数组

时间:2018-12-09 04:43:58

标签: javascript php arrays get

以下是我在javascript中的数组内容。我使用get调用将其传递到php页面。我也将其他数组与此数组一起传递。这些数组值被完全传递。仅此数组正在传递部分值。我也在javascript中警告它,并在其中完成了提醒。而在php中,它仅采用2个值而不是14。

var testPlanNameArray= ["Eligibility-Real Time Eligibility Cascading Validation", "Eligibility-SubmitterRouting", "Eligibility alias for defth", "Eligibility-Submitter x", "Eligibility-SubmitterRouting", "Eligibility-SubmitterRouting & Partner alias", "Eligibility-SubmitterRouting", "Eligibility-SubmitterRouting & Partne", "Eligibility-SubmitterRouting & Partner", "Eligibility-SubmitterRouting ", "Custom Maps Validation", "Custom Maps Validation", "Eligibility-Real Time Eligibility Custom Maps Validation", "Eligibility-Real Time Eligibility Custom Maps Validation"];

我正在使用下面的代码传递给php

$.get("dbValidation.php?&testIDArray=" + testIDArray + "&testPlanNameArray=" + testPlanNameArray + "&errorArray=" + errorArray + "&historyErrorDescArray=" + historyErrorDescArray  + "&expectedDEPProp=" + expectedDEPProp  + "&actualDEPProp=" + actualDEPProp).done(function(data3) {
                                // alert(testPlanNameArray);
                                        console.log(data3);
                                        console.log(testPlanNameArray);
                            });

我只是在php页面上做

<?php
$testPlanNameArray = explode(",", $_GET['testPlanNameArray']);
print_r($testPlanNameArray);
?>

当我执行console.log(data3)时,它将打印

Array
(
    [0] => Eligibility-Real Time Eligibility Cascading Validation
    [1] => Eligibility-SubmitterRouting 
)

我尝试了$ testPlanNameArray = json_decode($ _ GET ['testPlanNameArray']);但仍然没有完全价值。问题仅在于此阵列。对于其余阵列,它可以正常工作。

1 个答案:

答案 0 :(得分:1)

可能存在编码问题。我建议您将一个对象传递给=,它将对其进行正确编码。

$.get

这种编码实际上将在$.get("dbValidation.php", { testIDArray: testIDArray, testPlanNameArray: testPlanNameArray, errorArray: errorArray, historyErrorDescArray: historyErrorDescArray, expectedDEPProp: expectedDEPProp, actualDEPProp: actualDEPProp }).done(...) 参数中创建数组,因此您根本不需要使用$_GETexplode()

请注意,URL参数的长度通常受到限制,通常为1024或2048。因此,尝试在URL上传递长数组可能无法正常工作。您应该使用json_decode(),它具有更高的限制。