John Smith John Smith - 2 months ago 18
PHP Question

Accessing Data sent with JQuery AJAX with PHP

I am trying to make a shopping web platform and I use for every product a template that changes its data with data sent by AJAX post method.
JQuery:

$(".anunt .title").each(function() {
$(this).click(function() {
$.post("prodTemplate.php",{
title: $(this).html()
}, function() {
location.assign("prodTemplate.php");
});
});
});


PHP:

<div id="postare">
<?php
echo json_encode($_POST['title']);
?>
</div>


The error is: Undefined Index: title.
What am I doing wrong?

Answer Source

Maybe you should use the header tag to be able to access the variable from the other file.