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

170
Views
enviar y recibir una llamada ajax

Busqué años para evitar que esto sea un duplicado, pero parece que no puedo encontrar una respuesta.

En una página anterior de jquery, utilicé la siguiente llamada ajax:

 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); } });

Esto funcionó absolutamente a la perfección. events.php pudo recoger la variable usando:

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

Sin embargo, he llegado a usar una llamada AJAX diferente para enviar datos a una página diferente:

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

¡Sin embargo, no puedo por la vida en mí hacer que funcione! La página que debe recibir la llamada tiene este conjunto:

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

Cada vez, hello es todo lo que se repite. Intenté agregar y alertar para imprimirme los datos en caso de éxito, pero soy bastante nuevo en esto, por lo que simplemente impidió que funcionara por completo.

Mi conjetura (que no significa mucho) es porque esta variable es .val y no .html, por lo que depende del tipo de datos. Pero no estoy seguro de qué más puedo configurar esto.

Gracias por la ayuda.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Según su edición, parece que el problema es solo el tipo. El tipo predeterminado utilizado por el método $.ajax() de jQuery es GET. Para usar POST, debe especificar que:

 $.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); } });
about 4 years ago · Santiago Trujillo Report

0

A medida que publica datos con titleevent , los recibirá en el servidor como titleevent .

Tienes esto como tu código js:

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

Lo recibirás como:

 if(isset($_POST['titleevent'])) { $title = $_POST['titleevent']; echo "hooray found it"; } else { echo "hello"; }
about 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!