This question already has answers here:
Using Jquery Ajax to retrieve data from Mysql
(5 answers)
Updating a MySql database using PHP via an onClick javascript function
(2 answers)
How to update a web page without reloading the web page using AJAX?
(4 answers)
Closed 5 years ago.
I am new to javascript. I have one label, What I am doing is to get id using javascript which I am saving in a variable.
What I want is to send that variable to php page, where it will compare that id with mysql database id and returns it's data(some text) to javascript, it will then set it to label.
I would have used text file which is easiest way but some says this isn't a secure way to do this.
So how can I achieve this ?
Any help is appreciated, Thanks in advance.
Related
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
How do I pass JavaScript variables to PHP?
(16 answers)
Closed last month.
I am playing with PHP and Javascript. Also I am trying to find all possible ways to pass javascript variable into php variable in the same php file. So far, I have found two possible ways. One is well known to everybody which is ajax (i,e calling another php file). But it could not solve my problem easily. Another solution that I have figured out is utilizing COOKIE/SESSION. Here is my simple code example: It will alert 5 to 10. Javascript variable value 5 is passing inside php variable =>
<div id="one">5</div>
<script>
var vall = document.getElementById("one").innerHTML;
document.cookie = "val="+vall;
alert('<?php for($i=$_COOKIE["val"];$i<=10;$i++){echo $i;} ?>');
</script>
Do you have any other alternate or better solution?
This question already has answers here:
How do I pass variables and data from PHP to JavaScript?
(19 answers)
Closed 5 years ago.
I have a value sitting in my database which i want to use in an external JavaScript file. The JavaScript file is being referenced in the the html code using <script src="/thanks/thanks.js"></script>
Can anyone please help to figure out how i can either pass the value from php tp JavaScript or how i can access the database from the JavaScript?
The simple way is to use the <script> tag and echo the value you want to.
<?php
echo "<script>var parse = $value;</script>";
?>
Now you can use your value in javascript (parse variable). But if you want to have it detailed...
here is the duplicate you didnt search for: How to pass variables and data from PHP to JavaScript?
This question already has answers here:
UTF-8 all the way through
(13 answers)
How to store other languages (unicode) in cookies and get it back again
(1 answer)
Closed 5 years ago.
I'm building a references generator and I need to keep track of the generated references. To achieve this, I'm currently using Javascript to store a cookie containing the raw data, then a PHP page embedded on the result page takes the cookie and logs it into an HTML page, however, some characters appears like this : �. I really don't know which way to go to solve this (base64 encoding, unicode encoded characters...)
Here's the link to the website : http://louisfelixberthiaume.000webhostapp.com/source_siteweb.php
[It's in french]
I can't give you the link to the HTML page for obvious confidentiality reasons, however I'll provide a screenshot :
Generated references screenshot
This question already has answers here:
How do I access a JSON object using a javascript variable
(4 answers)
Closed 8 years ago.
My question is pretty simple. I have a json file stored and I fetch it using a simple xml request and store it for later use in the localstorage. Now What I need to do is that when the user selects something from the select tag, I fetch the value of the tag and use it get the data from json.
For ex:
database.Class.Teachers."The value from the select tag".age
Is this possible with javascript or similar workaround?
Ok i got the answer. Thanks.
link for the working code i found.
How do I access a JSON object using a javascript variable
This question already has answers here:
How to get client's IP address using JavaScript? [closed]
(31 answers)
Closed 9 years ago.
I want to find client's IP Address when accessing my app..How to find using javascript code..kindly provide help with sample code..I tried wit tis code but m not getting
function getip(json){
alert(json.ip); // alerts the ip address
}
You can't using ONLY JavaScript on it's own. You need to use a server side script ans call it using Ajax to perform this task.
For example in PHP script, you can do the following to get the client's ip address:
echo $_SERVER["REMOTE_ADDR"];
Next call this script using Ajax and display/use it in your page.
At least there used to be a way using Java to do this, but Javascript alone cannot find a machines IP.