Answer the question
In order to leave comments, you need to log in
How to pass variable values from JS to PHP via AJAX in one file?
There is a file 1.php in it there is a js code, there is a need to translate it into php.
I know that it can be done through ajax. I can pass values from js file to php.
$.ajax({
type: "POST",
url: "gen.php",
data: {"text" : new, "user_id" : user_id, "text" : text},
success: function(data){
title = data;
}
});
Answer the question
In order to leave comments, you need to log in
Alexander Wolf wrote to you, everything works
<?php if(isset($_POST['messag'])) {
exit($_POST['messag']);
}
?>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script type="text/javascript">
var messag = 'answer';
$.ajax({
type: "POST",
data: {
"messag" : messag
},
success: function(data){
console.log(data)
}
});
</script>
<?php
if(isset($_POST['user_id'])) {
// обрабатываем
}
?>
<script>
$.ajax({
type: "POST",
url: ".",
data: {"text" : new, "user_id" : user_id, "text" : text},
success: function(data){
title = data;
}
});
</script>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question