具體指標在我的代碼執行一個Ajax請求,並將其發送內容:
Object {appointment_data: "{"id_services":["13","13"],"id_users_provider":"86…lable":false,"id":"133","id_users_customer":"87"}", customer_data: "{"first_name":"Mario","last_name":"Rossi","email":…:"","city":"","zip_code":"","notes":"","id":"87"}"}
appointment_data: "{"id_services":["13","13"],"id_users_provider":"86","start_datetime":"2015-11-19 13:43:00","end_datetime":"2015-11-19 14:55:00","notes":"","is_unavailable":false,"id":"133","id_users_customer":"87"}"
customer_data: "{"first_name":"Mario","last_name":"Rossi","email":"[email protected]","phone_number":"0000","address":"","city":"","zip_code":"","notes":"","id":"87"}"
注:此內容包含在appointment
變量是JSON編碼:
JSON.stringify(appointment);
現在從PHP端,被調用的函數裏面,我試圖讓這種方式任命的id
:
$_POST['appointment_data']['id'];
但我得到這個錯誤:
Illegal string offset 'id'
我也試圖與.id
但同樣出現。
注意:如果我執行gettype()
我得到字符串$_POST['appointment_data']
也許這是問題嗎?我如何解決這個問題?
VAR DUMP PRINT
array(2) { ["appointment_data"]=> string(216) "{"id_services":["13","15","14"],"id_users_provider":"86","start_datetime":"2015-11-19 09:45:00","end_datetime":"2015-11-19 10:57:00","notes":"Appuntamento ","is_unavailable":false,"id":"131","id_users_customer":"87"}" ["customer_data"]=> string(146) "{"first_name":"Mario","last_name":"Rossi","email":"[email protected]","phone_number":"0000","address":"","city":"","zip_code":"","notes":"","id":"87"}" }
嘗試做'$ _POST ['appointment_data'] - > id;'(懷疑它會工作,但值得一試!) –
你不需要解析/解碼嗎? – FirstOne
與山姆提示我得到:消息:試圖獲得非物件的財產 我應該解析它? – Dillinger