First, let's look at a JS method of submitting an array by post:
var image = [' 20180512135343_564.png ', ' 20180512135156_860.png '];
$.post ('/community/community/add_community ', { ' type ': 1, ' title ': ' Tupianshangchuan ' , ' Image ': Image, },function(res) { console.log (res);});
Normally, an image is submitted to the background as an array:
Perhaps when you use some framework, the framework handles some of its own processing so that the data received in the background is in string form, such as "[' 20180512135343_564.png ', ' 20180512135156_860.png ']".
In this case, we can use json.stringify to submit an array of objects to a JSON-form string to avoid this phenomenon in the background. The code is as follows:
JS Code:
var image = [' 20180512135343_564.png ', ' 20180512135156_860.png '];$.post ('/community/community/ Add_community ', { ' type ': 1, ' title ': ' Tupianshangchuan ', ' image ': Json.stringify (image), },function(res) { console.log (res);});
PHP Receive,json_decode () function Processing:
$image $_post ("image"); $image _arr = Json_decode ($image,true);
JS commit array parameter, background Receive As String problem