Utilizing an API to update profile information allows for the addition of a nickname, email, phone number, or password in the request parameters, which will then be updated in the database.
When updating a specific field, such as Nickname:
{
"nickname": "alifa",
"device_id": "chrome",
"device_model": "browser",
"device_os": "angularJS"
}
Or when updating email:
{
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1f767179705f7a677e726f737a317c_7072">[email protected]</a>",
"device_id": "chrome",
"device_model": "browser",
"device_os": "angularJS"
}
To streamline this process, a function can be used to pass the property name and value, allowing for the creation of an object and sending an HTTP POST request:
this.updateDetails = function(dataName, dataValue){
Loader.global.show();
var data = $.param({
device_id: app.device_id,
device_os: app.device_os,
device_model: app.device_model
});
data[dataName] = dataValue;
console.log(data);
return $http.post(app.baseUrl + 'profile/' , data).success(function(){
Loader.global.hide();
}).error(function(){
Loader.global.hide();
})
}
However, the server is receiving only:
https://i.sstatic.net/DK29J.png
Is there a more efficient way to accomplish this task?