简体   繁体   English

如何将值传递给 ajax 响应并成功接收 function

[英]how to pass value to ajax response and receive in success function

i have array which i want to pass in ajax response我有一个数组,我想在 ajax 响应中传递

$val = [10 , 20 , 30];

here is i want to pass $val somtehing like this but i dont know the method这是我想像这样传递 $val somtehing 但我不知道该方法

return response()->json(['success'=> true, 'message' => 'Success' , 'val' ]);
 

this $val i dont know how i can pass and receive it in console here i want to receive这个$val我不知道如何在我想接收的控制台中传递和接收它

success: function (data) {

             if(data.success == true){
                 
                     toastr.success(data.message);
                     console.log(data.val);
             } 

can someone help me?有人能帮我吗? to receive value in console?在控制台中接收值?

You are not sending the val property in your response.您没有在响应中发送val属性。 So just like you have success and message in your json response, include a val property too and pass the $val variable.因此,就像您在 json 响应中successmessage一样,也包含一个val属性并传递$val变量。

try this试试这个

return response()->json(['success' => true, 'message' => 'Success' , 'val' => $val]);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM