The thought is so as to add two values and the overall of the sum put it aside or replace it in user_meta with jquery.ajax.
That is the code, but it surely provides me an error within the console Uncaught ReferenceError: ‘whole’ just isn’t outlined
Please, Any assistance is appreciated!
My Button
<a href="" onclick="CounterTrav()" id="btnTraPack"></a>
javascript
<script>
//This sum the tow values i get from a click on and works OK!
const clicksContainer = doc.querySelector('.clicksContainer');
const totalEl = doc.createElement('span');
clicksContainer.appendChild(totalEl);
clicksContainer.addEventListener('click on', operate(e) {
if (!e.goal.classList.comprises('clicksContainer')) {
const shareCLick = doc.querySelectorAll('.resultTraveler');
let whole = 0;
shareCLick.forEach(merchandise => {
whole += parseInt(merchandise.innerText, 10)
totalEl.innerHTML = whole
})
console.log(whole);
}
})
var clickCounterTrav = 0
operate CounterTrav() {
clickCounterTrav += 1;
doc.getElementById("resultTraveler").innerHTML = clickCounterTrav + " Travel Pack you have Shared!";
console.log(clickCounterTrav);
var CounterTrav_update = 'clickCounterTrav';
jQuery.ajax({
url: '/wp-admin/admin-ajax.php',
knowledge : {
motion : 'CounterTrav_update',
CounterTrav_value : CounterTrav_value,
},
beforeSend: operate() {
console.log('Updating Subject');
},
success : operate( response ) {
console.log('Success');
},
});
}
</script>
// MY ISSUE START HERE
If I take advantage of
var CounterTrav_update = 'clickCounterTrav';
The results of the sum is Appropriate, and the user_meta is Replace OK!, BUT solely replace "clickCounterTrav"
Like Eg: The person onready have in user_meta 2 clicks storage, and in session2 click on only one time, then replace user_meta with 1 worth.
PHP
add_action( 'wp_ajax_CounterTrav_update', 'CounterTrav_update' );
add_action( 'wp_ajax_nopriv_CounterTrav_update', 'CounterTrav_update' ); // This strains it is as a result of we're utilizing AJAX on the FrontEnd.
operate CounterTrav_update(){
if(empty($_REQUEST) || !isset($_REQUEST)) {
ajaxStatus('error', 'Nothing to replace.');
} else {
strive {
$person = wp_get_current_user();
$CounterTrav_value = $_GET['CounterTrav_value'];
update_user_meta( $user->ID, 'clickCounterTrav', $CounterTrav_value );
die();
} catch (Exception $e){
echo 'Caught exception: ', $e->getMessage(), "n";
}
}
}
If I take advantage of
var CounterTrav_update = 'whole';
Then the Sum result’s Nan and in Console error is: Uncaught ReferenceError: whole just isn’t outlined