jQuery Ajax PHP Tutorial : Swap out page content on your website using PHP
Why Stack Overflow recommends it
Stack Overflow users link it as a reference tutorial when asking about or answering jQuery Ajax and PHP content-swapping problems, including its swapContent example code.
Recommended by 0 people across 0 different months, 2011 to 2023.
What it is
A 2011 screencast by Adam Khoury showing how to use jQuery's $.post Ajax call to talk to a PHP script and swap the contents of a page element without reloading. It also touches on pulling data from a MySQL database through the same pattern.
What people said
Cites notlaura · 2011-09 · Stack Overflow · on “Move through PHP calendar months with jQuery AJAX”
I am creating an events calendar in a WordPress theme using David Walsh's calendar [LINK] function. I want to move between months with AJAX but am unfamiliar and having trouble posting and getting the month and year variables. I am referencing this AJAX video tutorial [this video] . At the top of the page template, I have this function: function swapContent(month,year) { jQuery("#calendar").html("<img src='images/ajax-loader.gif'>").show(); var url="calendar.php"; jQuery.post(url, {contentVar: month, year}, function(data){ jQuery("#calendar").html(data).show(); }); } In calendar.php: $month = (int) ($_GET['month'] ? $_GET['month'] : date('m')); $year = (int) ($_GET['year'] ? $_GET['year'] : date(
Cites Val · 2011-12 · Stack Overflow · on “jQuery hide form on submit?”
I think the reason it may not work is because the form is submitting it's data and waiting for page to refresh... which means, it will stop all of it's javascript stuff coz it's pointless ... I could be wrong but hey, your hide would take 1 second to hide but your page could reload quicker. $(document).ready(function() { $('div.mainsuccess,div.mainerror').hide(0).fadeIn(1000); $('form.register').submit(function(e) { e.preventDefault();// will stop the form being submited... $(this).hide(1000); // do ajax here... return false; }); }); Updated here is a list of tutorials [LINK] [LINK] [LINK] Videos .... [this video]
Cites DrDevDoctrina · 2023-01 · Stack Overflow · on “I'm doing my first ever jQuery and getting told it's not a defined function”
Trying to use this code to change content on a page without reload. It's my first time playing with jQuery. I keep getting this error: Uncaught ReferenceError: swapContent is not defined at HTMLButtonElement.onmousedown This is the code: <script type="/text/javascript" src="jquery-1.5.1.js"></script> <script language="JavaScript" type="/text/javascript"> function swapContent(cv){ "use strict"; $("#myDiv").html("").show(); var url="main_views.php"; $.post(url, {contentVar: cv},function(data){ $("#myDiv").html(data).show(); }); } </script> It's actioned by these buttons: <button href="#" onClick="return false" onmousedown="javascript:swapContent('con1');">View One</button> •