ST can package the data into json and send it to the php side cartItemsStoreExt. getStore (cartitemsconvert); varallData []; cartItemsStore. each (function (records) {allData. push (records. getData () ;}); vardataToBeSentToServerExt. JSON. encode (allData); console. lo
ST can package data in json format and send it to cartItemsStore = Ext. getStore ('cartitemsconvert'); var allData = []; cartItemsStore. each (function (records) {allData. push (records. getData () ;}); var dataToBeSentToServer = Ext. JSON. encode (allData); console. lo
ST can package the data into json format and send it to the php end.
cartItemsStore = Ext.getStore('cartitemsconvert');var allData = [];cartItemsStore.each(function(records){allData.push(records.getData());});var dataToBeSentToServer = Ext.JSON.encode(allData);console.log(dataToBeSentToServer);
Then use jsonp or ajax to transmit data to the PHP end.
Ext. data. jsonP. request ({url: 'http: // callback, callbackKey: 'callback', params: {sendData: dataToBeSentToServer}, timeout: 2000, success: function (result, request) {console. log ('data submitted successfully ');}});
Then how does PHP obtain the json data? The red part is a php issue. If the stripslashes conversion is not required. The stripslashes () function deletes the backslash added by the addslashes () function. Otherwise, The data is printed out empty. Another solution is: The fix was to turn off magic_quotes in php. ini. if you do this, you will no longer need the call to stripslashes ().
$sendData = $_REQUEST['sendData'];$jsondata = stripslashes($sendData);//$sendData = '[{"id":"1","food":"\u5f20\u96ea\u6885","age":"27","subject":"\u8ba1\u7b97\u673a\u79d1\u5b66\u4e0e\u6280\u672f"},{"id":"2","food":"\u5f20\u6c9b\u9716","age":"21","subject":"\u8f6f\u4ef6\u5de5\u7a0b"}]';$arrayData = json_decode($jsondata);foreach($arrayData as $obj){echo "id:".$obj->food."
";}
Two Methods for parsing json data are attached to PHP:
There are two methods to process JSON strings in PHP code: the only difference is that highlight has come out.
Method 1:
$ Json = '[{"id": "1", "name": "\ u5f20 \ u96ea \ u6885", "age": "27", "subject ": "\ u8ba1 \ u7b97 \ u673a \ u79d1 \ u5b66 \ u4e0e \ u6280 \ u672f" },{ "id": "2", "name ": "\ u5f20 \ u6c9b \ u9716", "age": "21", "subject": "\ u8f6f \ u4ef6 \ u5de5 \ u7a0b"}] '; $ students = json_decode ($ json); // The objectforeach ($ students as $ obj) {echo "name :". $ obj-> name. "Age :". $ obj-> age. "Major :". $ obj-> subject."
";}
Method 2:
$ Json = '[{"id": "1", "name": "\ u5f20 \ u96ea \ u6885", "age": "27", "subject ": "\ u8ba1 \ u7b97 \ u673a \ u79d1 \ u5b66 \ u4e0e \ u6280 \ u672f" },{ "id": "2", "name ": "\ u5f20 \ u6c9b \ u9716", "age": "21", "subject": "\ u8f6f \ u4ef6 \ u5de5 \ u7a0b"}] '; $ students = json_decode ($ json, true); // arrayfor ($ I = 0; $ I
";}