Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

178
Views
sending and recieving an ajax call

I looked for ages to prevent this being a duplicate but i can't seem to find an answer.

On a previous jquery page i used the following ajax call:

var daynum1 = $(this).text();
var month1 = $('.ui-datepicker-month').text();
var year1 = $('.ui-datepicker-year').text();
var myDate = daynum1 + " " + month1 + " " + year1;
$('#headingcontent').html(myDate);

$.ajax({
  url: "events.php",
  type: "POST",
  data: { myDate: myDate },
  dataType: "html",
  success: function(html) {
    $("#eventcontent").empty();  
    $("#eventcontent").append(html);
  }
});

This worked absolutely perfectly. events.php was able to pick up the variable using:

if(isset($_POST['myDate']))

However I've come to use a different AJAX call to send data to a different page:

var titleevent = $("#dropdowntextbox").val();

$.ajax({
  url: "editevents2.php",
  cache: false,
  data: { titleevent: titleevent },
  dataType: "html",
  success: function(html) {
    $("#editeventspopup").empty();  
    $("#editeventspopup").append(html);
  }
});

However I can't for the life in me get it working! The page that should receive the call has this set:

if(isset($_POST['titleevent']))
{
  $title = $_POST['titleevent'];
  echo "hooray found it";
}
else
{
  echo "hello";
}

Every single time, hello is all that is echoed. I've tried to add and alert to print the data back to me on success but i'm quite new to this so it just stopped it from working altogether.

My guess (which doesn't mean much) is because this variable is .val and not .html so its down the the data type. But i'm not sure what else i can set this to.

Thanks for the help.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Based on your edit it seems that the problem is just the type. The default type used by jQuery's $.ajax() method is GET. In order to use POST, you need to specify that:

$.ajax({
  url: "editevents2.php",
  type: "post",  // specify the type as POST
  cache: false,
  data: { titleevent: titleevent },
  dataType: "html",
  success: function(html) {
    $("#editeventspopup").empty();  
    $("#editeventspopup").append(html);
  }
});
over 4 years ago · Santiago Trujillo Report

0

As you are posting data with titleevent you will receive this on the server as titleevent.

You have this as your js code:

var titleevent = $("#dropdowntextbox").val();

 $.ajax({
  url: "editevents2.php",
  cache: false,
     data: {titleevent: titleevent},
     dataType: "html",
  success: function(html){
    $("#editeventspopup").empty();  
    $("#editeventspopup").append(html);
  }
});

You will receive it as:

if(isset($_POST['titleevent']))

        {

           $title = $_POST['titleevent'];

echo "hooray found it";

        }

        else
        {

echo "hello";
        }
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!