The thing is, I use Ajax and back-end interaction, need to send a bunch of data to the backend, I put the data encapsulated a bit after the format is the following! This is what I send_data in the AJAX function below.
The data is an array of objects, with two keys in the number of groups, Role_code and User_list, respectively. Where User_list is also the default is an array, can be empty.
This array has been successfully sent to the backend, that is, the length inside is 0 user_list back end gets not! The User_list backend, which is not 0 in length, is available
So I went to the browser to view the request information and found that I did not seem to have a few empty arrays sent past.
I was puzzled that the Jqeury Ajax function could not pass an empty array over it? Attached to my Ajax code, where the send_data is the data I started to play.
$.ajax({ url:"
"+"/"+$(this).parents(".modal-content").attr("id"), type:"POST", data:{send_data}, dataType:"json", success:function (data) { if (data.status==1) { alert("成功!"); location.reload(); }else{ alert("失败!"); } }})
Ask the great God for answers!
Reply content:
The thing is, I use Ajax and back-end interaction, need to send a bunch of data to the backend, I put the data encapsulated a bit after the format is the following! This is what I send_data in the AJAX function below.
The data is an array of objects, with two keys in the number of groups, Role_code and User_list, respectively. Where User_list is also the default is an array, can be empty.
This array has been successfully sent to the backend, that is, the length inside is 0 user_list back end gets not! The User_list backend, which is not 0 in length, is available
So I went to the browser to view the request information and found that I did not seem to have a few empty arrays sent past.
I was puzzled that the Jqeury Ajax function could not pass an empty array over it? Attached to my Ajax code, where the send_data is the data I started to play.
$.ajax({ url:"
"+"/"+$(this).parents(".modal-content").attr("id"), type:"POST", data:{send_data}, dataType:"json", success:function (data) { if (data.status==1) { alert("成功!"); location.reload(); }else{ alert("失败!"); } }})
Ask the great God for answers!
Strict control format:
Data:JSON.stringify (Send_data)
By the way, the front and back end of a good format, after the first side of the switch to JSON encoding, it is possible to pass an empty array (of course, after the code is not called an array).
Back-end (PHP) Json_decode () on the line.
Finally say a bit more, the front-end code inside the PHP code feel a bit ugly ...
The name value Plus
data:{user_list:send_data},
$.ajax({ type: "POST", url: '', dataType:'json', data: { 参数A: 参数A的值, 参数B: 参数B的值 }, success:function(result){ if (result.success) { }else{ } } });