Jquery 如何将多个参数从服务器发送到js映射
在我的Laravel5.7/jQuery3应用程序中,我需要从服务器发送几个参数Jquery 如何将多个参数从服务器发送到js映射,jquery,laravel-5,Jquery,Laravel 5,在我的Laravel5.7/jQuery3应用程序中,我需要从服务器发送几个参数 $retArray= ['error_code' => 0, 'message' => '']; foreach( $requestData as $next_param_name ) { if( $next_param_name == 'customerAccountTypeValueArray' ) { $retArray['customerAccountTypeValue
$retArray= ['error_code' => 0, 'message' => ''];
foreach( $requestData as $next_param_name ) {
if( $next_param_name == 'customerAccountTypeValueArray' ) {
$retArray['customerAccountTypeValueArray']= Customer::getCustomerAccountTypeValueArray(false);
}
if( $next_param_name == 'customerStatusValueArray' ) {
$retArray['customerStatusValueArray']= Customer::getCustomerStatusValueArray(false);
}
}
return response()->json( $retArray, 200);
而数组retArray包含如下数据:
Array
(
[error_code] => 0
[message] =>
[customerAccountTypeValueArray] => Array
(
[I] => Individual
[B] => Business
)
[customerStatusValueArray] => Array
(
[A] => Active
[I] => Inactive
[N] => New
)
)
但我发现了Javascript错误:
Error in render: "TypeError: selectionsList.map is not a function" found in
使用我的JS代码:
post('/api/dashboard settings',paramsArray)
。然后((响应)=>{
看起来selectionsList不像我想象的那样是元素数组。哪种方法正确
修改:
这就是我在浏览器控制台中查看服务器数据的方式:
后来我把它设为参数。
谢谢!尝试返回对象数组,并确认数据:
$tempDataArray= Model::getSomeDataArray();
$retArray= [];
foreach( $tempDataArray as $next_key=>$next_value ) {
$retArray[]= (object)$next_value;
}
return response()->json( $retArray, 200);
请看修改后的方块
$tempDataArray= Model::getSomeDataArray();
$retArray= [];
foreach( $tempDataArray as $next_key=>$next_value ) {
$retArray[]= (object)$next_value;
}
return response()->json( $retArray, 200);