POST Method posting extra items

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

{
	"names": {
		"_origin": -489,
		"_subscribers": [
			{
				"version": 2,
				"active": true
			}
		],
		"_isProxy": false,
		"_values": [
			"JERMAINE COLE"
		],
		"_beganSubscriptions": true
	}
}

What could be the problem ? All I want is the data under ‘_values’ and not the rest.

Also, what’s the best way to decode the JSON using PHP on the server side ?
I have been trying the code below and it has not been successful yet :

<?php
	# Get JSON as a string
	$json_str = file_get_contents('php://input');

	# Get as an object
	$json_obj = json_decode($json_str);

        ....

Someone please help out. I would really appreciate it guys!
Thanks in advance.

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.

Hi there, thanks for getting back to me.

I don’t exactly know where the serialising is happening so I’d be grateful if you go through my code and help me find the needle in the haystack.

Link : https://pastebin.com/QB8n0LME

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.

Thanks in advance sir.

There’s not much to look for really, it’s right there:

        var userfullnames = Observable();
        // ...
            requestObject = {
                names : userfullnames,
                // ...
            };

If all of your observables up there are single-value observables, you can just change your requestObject to this:

var requestObject = {
    names : userfullnames.value,
    phonenumber : userphonenumber.value,
    carnumberplate : carnumberplate.value,
    carmodel : carmodel.value,
    problem : carproblemdetails.value,
    latitude : latitude.value,
    longitude : longitud.valuee
};

It seems to me that you should spend some time reading about Observables to get a better understanding on how they work.

Hope this helps!

Thanks so much for the input. I highly appreciate it.

I will do the corrections to the code and get back to you on the progress.

Thanks, again.

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.

What might be the cause ?
Thanks in advance.

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.