I have a string in javaScript.
<script type="text/javascript">
Var string='String to use';
</script>
Now i want to access text of string in php. How can i access it. Or use it.
asked Mar 13, 2014 at 16:41
Zia ur Rehman
4291 gold badge4 silver badges22 bronze badges
2 Answers 2
You will have to make an ajax call if you don't want to reload the page else add it to a hidden form field and submit. I usually do it in jQuery like this-
$.ajax({
url:"demo_test.txt",
data:{
variable_name_in_php_script:variable_name_in_javascript
}
success:function(result){
//process result
}});
answered Mar 13, 2014 at 16:42
halkujabra
2,9524 gold badges28 silver badges38 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
Not sure but this might be of help to you. I hope everything works out.
http://w3epic.com/how-to-pass-variable-from-php-to-javascript-javascript-to-php/
1 Comment
Oriol
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
default
varshould be written in lowercase