Hi there, I have some TextInputs that capture data and using fetch, send them to my server for storage - as POST JSON.
Here is the JavaScript method to send the data :
function sendBreakdownRequest() {
requestObject = {
names : userfullnames,
phonenumber : userphonenumber,
carnumberplate : carnumberplate,
carmodel : carmodel,
problem : carproblemdetails,
latitude : latitude,
longitude : longitude
};
fetch('http://****/breakdowntest.php', {
method: 'POST',
headers: { "Content-type": "application/json"},
body: JSON.stringify(requestObject)
}).then(function(response) {
status = response.status; // Get the HTTP status code
response_ok = response.ok; // Is response.status in the 200-range?
return response.json(); // This returns a promise
}).then(function(responseObject) {
// Do something with the result
}).catch(function(err) {
// An error occurred somewhere in the Promise chain
});
}
However, the JSON on the server end ends up with extra data i.e
The fact that you’re receiving those additional properties means that you’re serialising and sending over an Observable. The snippet you posted does not explain how you end up doing that, so please show more of your actual code.
As for the PHP side, json_decode is pretty much all you need. Make sure you get the right string in input and you’re all set.
IDEA : I’m building a simple breakdown app that gets your location and some few other details, which are then sent to the server, so that a breakdown service can be sent to your location. It’s for a school project.
Hi there,
Thanks alot for your input. Now the data is being sent as I wanted it to.
However, my GeoLocation isn’t working or something is messing up. I’m using the continuous method to change the longitude and latitude values. On the device, with the ShowMyLocation="True" ShowMyLocationButton="true" attributes, the MapView shows the current location. However, the variables are not updated. Hence, when the data is sent, the values appear as 0 and 0.
That’s not a question related to the one handled in this thread. Please make a new forum post and include a complete, minimal reproduction along with other useful details, such as the target device you’re testing on.