Dies ist mein 1. Mal mit AngulerJS. Ich versuche POST
Daten an den Server.nicht in der Lage, richtige Daten mit AngularJS Post-Methode zu erhalten
AngularJS-Code
var app = angular.module("myApp", []);
var BASE_URL = "http://localhost/project/api/Data/";
var GET_DATA = BASE_URL+"get_data";
console.log(GET_DATA);
app.controller('myCtrl', function($scope, $http) {
var inputs = { "user_id": "3"};
var config = {
headers : {
'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8;'
}
}
$http.post(GET_DATA , inputs, config)
.success(function (response, status, headers, config) {
$scope.content = response.error;
$scope.statuscode = response.status;
$scope.statustext = response.statusInfo;
console.log(response);
})
.error(function (data, status, header, config) {
$scope.ResponseDetails = "Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + header +
"<hr />config: " + config;
});
});
Diese Codedaten auf dem Server veröffentlichen, aber mit etwas verdrahteten Format. Unten ist mein print_r($_POST);
Ergebnis:
Array
(
[{"user_id":"3"}] =>
[0] =>
)
das falsche Ergebnis ist, erwarte ich so etwas wie
Array
(
user_id => 3
)
Hinweis: auf Server-Seite Ich benutze CodeIgniter Rahmen.
'var inputs =" user_id = 3 ";' –
@MayankVadiya was ist, wenn ich mehrere Schlüssel senden möchte: value? und Dateien sowie – AkshayP
als Sie '&' verwenden können. –