This is how I submit the form
$http({
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
method: 'POST',
url: url,
data: {
type: 1
}
})
Why does my server receive something like this?
{ '{"type":1}': '' }
Problem solved
Reason:
By default, jQuery transmits data using Content-Type: x-www-form-urlencoded and the familiar foo=bar&baz=moe serialization. AngularJS, however, transmits data using Content-Type: application/json and { "foo": "bar ", "baz": "moe" } JSON serialization
By default, jQuery transmits data using Content-Type: x-www-form-urlencodedand and a sequence similar to "foo=bar&baz=moe", whereas AngularJS, transmits data using Content-Type: application/json and { "foo ": "bar", "baz": "moe" } Such json sequence.
Solution
Maybe you are used to using jquery,
jquery encapsulates the query_string operation
Just add this code to angular and change the example name
1. Read the official documentation of angularjs to understand its usage. It seems that the header of $http is a little different.
2. Download the fiddler tool and view information such as request headers and params.
The server cannot directly use $_REQUEST/$_POST to obtain it, but needs to use:
$params = json_decode(file_get_contents('php://input'),true);
To get submission data