Answer the question
In order to leave comments, you need to log in
Send data via ajax to $_SESSION variable?
Good evening. I can't set up the ajax request handler in any way so that it adds data to the $_SESSION variable.
Here is the code below:
The form with which the request occurs
<div id='product_add_result'></div>
<form method="get" action="//work.shucach.freedomain.thehost.com.ua/wp-content/themes/work-and-travel-child/add.php" class='product_add'>
<input type="text" name="unit" value="1">
<input type="submit" value="добавить" name="nevvalue">
</form>
$(function(){
// откуда берем данные сформы
$('.product_add').submit(function(e){
//отменяем стандартное действие при отправке формы
e.preventDefault();
//берем из формы метод передачи данных
var m_method=$(this).attr('method');
//получаем адрес скрипта на сервере, куда нужно отправить форму
var m_action=$(this).attr('action');
//получаем данные, введенные пользователем в формате input1=value1&input2=value2...,
//то есть в стандартном формате передачи данных формы
var m_data=$(this).serialize();
$.ajax({
type: m_method,
url: m_action,
data: m_data,
success: function(result){
// где показываем результат
$dd = result;
$_SESSION['id'] = $dd;
$('#product_add_result').html($dd);
}
});
});
});
<?
echo $_GET['unit']
?>
Answer the question
In order to leave comments, you need to log in
I'm wildly surprised that you wrote "everything works", but if specifically on the problem, then look in the developer panel what data you have going to the server, you can remove ['unit'] and put var_dump($_GET)
and I'm surprised specifically by this line
$_SESSION['id'] = $dd;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question