I’m a complete and utter AJAX noob and have been sitting with the same problem for the last 3 hours. I’m trying to display a dynamically generated calendar (generated via PHP using a database). But before I continue, here’s my javascript…
The calendar does display when the loadURL function is called, but doesn’t display using the paramaters defined in the “params” variable, it defaults to the current month (that’s part of my php script, so it’s supposed to do that). So, it seems to me that xmlhttp.send(params) isn’t actually sending the desired paramaters.
Can anyone please help me with this, as I am running short on hair. Thanks
Hi Jim! Thanks so much for the reply! Yes, I have tested it like that, and it works fine. The script was originally written in PHP (with page reloads) and the AJAX was kind of an afterthought. If I change the script as follows…
xmlhttp.open('POST', url);
it works just fine. But I can’t for the life of me get the xmlhttp.open(params) statement to work.
Let me paste my PHP calendar script, so you can see what it does…
I don’t do much PHP but doesn’t the $_GET variable contain stuff sent using the GET method? Shouldn’t you use $_POST for stuff sent via POST? (or er $_REQUEST for either I think, isnt it?)
$_GET[‘name’] contains “Tom” and $_GET[‘surname’] contains Harrison in this particular instance.
With my previous post I mean to say that I took out the xmlhttp.send(params) completely and simply changed xmlhttp.open(“POST”, url) to xmlhttp.open(“POST”, “calendar.php?year=2007&month=8”) and it loaded everything correctly, so I don’t think there’s anything wrong with the PHP anyway. For some reason however, xmlhttp.send(params) is still not sending the required variables to the calendar.php file.
When you send a request for a page in that format, I would expect $_GET to work fine (no matter if the request you are sending is a POST) as you have illustrated here:
xmlhttp.open(“POST”, “calendar.php?year=2007&month=8”);
xmlhttp.send(“whatever, it doesn’t matter”);
But if you want to send the variables via POST, ie
xmlhttp.open(“POST”, “calendar.php”);
xmlhttp.send(“year=2007&month=8”);
you will need to use the $_POST collection server side.