Answer the question
In order to leave comments, you need to log in
ajax problem?
I need to send an array to the server, for some reason [Object object] is sent, if you look through console.log, then the output is normal, but on the server it is already [Object object]
array_setting = {
addresses: [
{
type: 'home',
street1: $('.block-info #street1').text(),
street2: $('.block-info #street2').text(),
city: $('.block-info #city').text(),
state: $('.block-info #state').text(),
zip_code: $('.block-info #zipCode').text(),
country: $('.block-info #country').text()
}
],
date_of_birth: $('.block-info #dateOfBirth').text(),
emails: [
{
type: 'default',
email: $('.block-info #email').text()
}
],
gender: {
"id": $('.block-info #gender').attr('data-id'),
},
name: {
first_name: $('.block-info #firstName').text(),
last_name: $('.block-info #lastName').text(),
preferred_name: ""
},
phones: [
{
type: 'emergency',
area_code: $('.block-info #phoneEmergency').attr('data-code'),
number: $('.block-info #phoneEmergency').attr('data-number'),
extension: "",
},
{
type: "home",
area_code: $('.block-info #phoneEmergency').attr('data-code'),
number: $('.block-info #phoneEmergency').attr('data-number'),
extension: "",
}
],
};
$.ajax({
url: '<?php echo admin_url( "admin-ajax.php" ) ?>',
type: 'POST',
data: 'action=editAccount&settings=' + array_setting,
success: function( data ) {
console.log(data);
}
});
Answer the question
In order to leave comments, you need to log in
$.ajax({
url: '<?php echo admin_url( "admin-ajax.php" ) ?>',
type: 'POST',
data: {
action: 'editAccount',
settings: array_setting,
},
success: function( data ) {
console.log(data);
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question