Answer the question
In order to leave comments, you need to log in
How to pass data from jquery to php?
It is necessary that when selecting an item in the select, dynamically receive its value and work with it using php.
As I understand it, all this is implemented through ajax.
I found an example that, in theory, sends data to 'post.php' and outputs it to the console in parallel. The question is how to get data from post.php?
<head>
<title>titile</title>
<meta charset="utf-8">
<style>
</style>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script>
$(function(){
$('#company-list').on('change', function(event) {
console.log($(this).val());
$.ajax({
url: 'post.php',
type: 'POST',
dataType: 'html',
data: {idCompany: $(this).val()},
})
.done(function() {
console.log("success");
})
.fail(function() {
console.log("error");
});
});
});
</script>
</head>
<body>
<select id="company-list">
<option value="1">Компания 1</option>
<option value="2">Компания 2</option>
<option value="3">Компания 3</option>
<option value="4">Компания 4</option>
</select>
</body>
</html>
echo $_POST['idCompany'];
Answer the question
In order to leave comments, you need to log in
The question is how to get data from post.php?What will be displayed in this file through
echo
or another output statement, as well as outside the php brackets, will come as a response. .done(function(data) {
console.log(data);
})
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question