John John - 1 year ago 81
Ajax Question

Post data to another php page using ajax

I use the Fullcalendar (javascript). When you click on the event it opens a form with its content.

eventClick: function(calEvent, jsEvent, view) {

content.val(calEvent.content); //content of event


I want to do that when you click on the event its opens another php page and displayed its data in it. For now i am trying to just send "hello" string to PAGE2.

eventClick: function(calEvent, jsEvent, view) {

var content = "hello";


cache: false,
dataType: "text",
url: "page2.php?id=<?php echo $_SESSION['id']?>",
data: { content: content },

success: function(data){
location.href = 'page2.php?id=<?php echo $_SESSION['id']?>';


$content = $_POST['content'];
echo $content;

In browser, i see that when you click on an event it performed POST request on PAGE2 with FORM DATA: content:hello. Then there is a transition to PAGE2 and some GET requests without data. And on the PAGE2 i see the error: Undefined index: content.

I spent so many days trying to solve this problem, but have not found a solution. Please, help me to understand where the error is.

Answer Source

seems like you could create a <form method='post' action='page2.php?id=....' with a hidden input named content, then call the forms submit function in your onClick after it has filled in the hidden inputs value to the content you need

a bit like

<form id ="theForm" action="page2.php?id=<?php echo $_SESSION['id']?>" method="POST">
    <input type="hidden" name="content" id="content"/>
    eventClick: function (calEvent, jsEvent, view) {
        var content = document.getElementById('content');
        var form = document.getElementById('theForm');
        content.value = 'hello'; // based on your example, obviously you need a value based on the click
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download