Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

176
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda