The current situation is that the back-end uses the php yii framework to return data to the front-end in view mode. There is a form that binds the onclick event and sends the data requests obtained by php to another backend, that is, the following sendAction. php. Problem: the current situation of jQuery's se... is that the back-end uses the php yii framework to return data to the front-end through the view method.
There is a form that binds the onclick event and sends the data requests obtained by php to another backend, that is, the following sendAction. php.
Question: After the serializeArray () method of jQuery is assigned a value, an object is generated. How can I assign a value to this object? (For example, the code below, $ results obtained through php, assign values to the postdata object for sendAction. php can accept this value )? The following code shows that the results corresponding to the key is passed, but the results value is not passed. If it is printed on the backend, it is displayed as [object].
Function doAction (id) {var url = 'sendaction. php'; var postdata = $ ("# form "). serializeArray (); postdata [postdata. length] = {name: 'id', value: id}; var results =
$ Results)?>; Postdata [postdata. length] = {name: 'result', value: results}; $. ajax ({type: "POST", url: url, data: postdata, // dataType: "json", success: function () {alert ("sent successfully ");};});}
Reply content:
The current situation is that the back-end uses the php yii framework to return data to the front-end in view mode.
There is a form that binds the onclick event and sends the data requests obtained by php to another backend, that is, the following sendAction. php.
Question: After the serializeArray () method of jQuery is assigned a value, an object is generated. How can I assign a value to this object? (For example, the code below, $ results obtained through php, assign values to the postdata object for sendAction. php can accept this value )? The following code shows that the results corresponding to the key is passed, but the results value is not passed. If it is printed on the backend, it is displayed as [object].
Function doAction (id) {var url = 'sendaction. php'; var postdata = $ ("# form "). serializeArray (); postdata [postdata. length] = {name: 'id', value: id}; var results =
$ Results)?>; Postdata [postdata. length] = {name: 'result', value: results}; $. ajax ({type: "POST", url: url, data: postdata, // dataType: "json", success: function () {alert ("sent successfully ");};});}
var results =
$results))?>;
Equivalent to var results = {results: theJsonObject}; right?
When http is used to transmit data, it is impossible to pass the array to php. Instead, it is a string in a specific format, which may be a json string or xml string, maybe it is the common key1 = value1 & key2 = value2 method, OK?
Therefore, when ajax is submitted, it will inevitably convert postdata to a string. When postdata is a nested array, problems may occur, which leads to your problems.
We recommend that you change the above line
var results = '
$results))?>';
This is equivalent to var results = '{results: theJsonObjct}'. It is a common string. After the php end is obtained, json_decode can be restored. What do you think?