我正在使用Angular.js應用程序,我必須向PHP服務器發送POST請求。我發送的數據是對象的對象。
喜歡的東西:
var data = {
"serviceID": "0001",
"interpreterDetails": {
"firstName": "Peter",
"lastName": "Wilson",
"password": "Peter",
"rePassword": "Peter",
"address": "alex",
"mobPhone": "01224747748",
"homePhone": "3910009",
"mail": "[email protected]",
"fax": "556",
"hourlyRate": "10",
"OperatingSys": "android",
"token": "432132",
"dialectId": "1"
}
}
當我將使用這個對象的角度
$http({
url: "http://localhost/saveInterpreter.php",
method: "POST",
data: $httpParamSerializer(data),
headers : {
"Content-Type": "application/x-www-form-urlencoded; charset=UTF-8;"
}
})
,並在服務器代碼返回
object(stdClass)#3 (9) {
["interpreterDetails"]=>
string(262) " {"firstName":"Peter","lastName":"Wilson","password":"Peter","rePassword":"Peter","address":"alex","mobPhone":"01224747748","homePhone":"3910009","mail":"[email protected]","fax":"556","hourlyRate":"10","OperatingSys":"android","token":"432132","dialectId":"1"}"
["serviceID"]=>
string(4) "0001"
}
,但預期收益
object(stdClass)#3 (8) {
["serviceID"]=>
string(4) "0001"
["interpreterDetails"]=>
object(stdClass)#4 (13) {
["firstName"]=>
string(5) "zxczc"
["lastName"]=>
string(4) "zxcz"
["password"]=>
string(4) "1234"
["rePassword"]=>
string(4) "1234"
["address"]=>
string(4) "sada"
["mobPhone"]=>
string(4) "4532"
["homePhone"]=>
string(4) "1351"
["mail"]=>
string(11) "[email protected]"
["fax"]=>
string(6) "123513"
["hourlyRate"]=>
string(2) "26"
["OperatingSys"]=>
string(0) ""
["token"]=>
string(0) ""
["dialectId"]=>
string(1) "1"
}
}
問題是,對象內部(interpreterDetails)外部對象(數據)被返回爲字符串而不是對象。
與
注意任何幫助:當我使用jQuery它返回預期的結果