目前我正在使用下面的代碼,它工作正常。角度:通過表單提交附加數據
$scope.processForm = function($scope.formData) {
$http({
method : 'POST',
url : 'process.php',
data : $.param($scope.formData), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
})
現在我有一個小的要求。我需要傳遞用戶標識(uid)以及表單數據。 在jquery中它很簡單,但我是新來的角度和沒有太多的經驗。
任何建議如何我可以在Angular中傳遞額外的數據。
感謝
你可以用你的uid參數togheter封裝你FORMDATA在對象expl:'var allData = {'formData':$ scope.formData,'uid':$ scope.uid}',然後將allData對象傳遞給post方法'data:allData' –
formdata爲空。我不知道爲什麼。 – Ironic
試試這個: 1-Remove'headers:{'Content-Type':'application/x-www-form-urlencoded'}' 2 -in your process.php: '$ postContent = file_get_contents(「php: //輸入「); $ req = json_decode($ postContent); $ formData = $ req-> formData; $ uid = $ req-> uid;' –