Is it possible to store a resulting php variable into localStorage?
You can store directly like this, as long as you got PHP has this data with you in the same page
<script>
localStorage.setItem('php_var', "<?php echo $var;?>");
</script>
Sending a localstorage variable to PHP
echo
$userMark
in marks.php
marks.php
<?php
echo $userMark = $_POST['userMark'];
echo $userMark;
?>
profile.php
and alert data
in javascript
$(document).ready(function(){
var userMarkVar = localStorage.getItem("userMark");
jQuery.post("marks.php", {userMark: userMarkVar}, function(data){
alert(data);
}).fail(function(){
alert("Error");
});
});
Get localStorage value into php
You can not directly get a localStorage value in PHP, when script is executed, because localStorage is contained in user's browser, and PHP is running on server. However, you can send the value from localStorage to a server with GET or POST request.
Send Javascript local storage variables to MySql database using JQuery
When using Ajax I recommend trying the non-shorthand:
$.ajax({
type: "POST",
url: 'auditConfirm.php',
data: {
jsAuditPercentage: localAuditPercentage,
jsVenuePercentage: localVenuePercentage,
}
});
This solution works on my end.
Related Topics
Reprompt for Permissions With Getusermedia() After Initial Denial
How to Highlight Parts of an Imagemap on Mouseover
Reduce the Build Time in a Large Angular 8
How to Wait Until 2 $Http Requests End in Angularjs
Get Part of the Url Pathname Via JavaScript Regex
Jquery Do Not Allow Alphabets to Be Entered in Input Field
Convert Date String from Yyyymmdd to Dd Mon Yyyy
How to Get the Difference Between Two Arrays of Objects in JavaScript
How to Resolve the C:\Fakepath
Getting an Array of Column Names At Sheetjs
Show Multiple Divs on Button Click
Prevent Any Form of Page Refresh Using Jquery/Javascript
Filtering Item from Nested Object Array in Typescript
Refresh Leaflet Map: Map Container Is Already Initialized
How to Print Image from Browser Using JavaScript
React Enable Button After All Form Fields Are Not Empty
How to Add Scroll Event in React Component
Count Total Number of Checkboxes What Are Checked and Show on Page Via Js