jimfog Posted June 25, 2013 Share Posted June 25, 2013 This is the PHP code that changed the day in a calendar(the calendar always shows the current day and with code shown belowthe user can go back or forward day by day). datecalculation($newdate);if (isset($_GET['newdate'])) { $newdate = $_GET['newdate']; datecalculation($newdate);} <ul id="dayshow"> <li><a href="<?php echo $_SERVER["PHP_SELF"]. "?newdate=". $prevDay . '&dayview' ?>"><img id="prevday" src="Images/day_prev.png"></a></li> <li><?php echo $now->format('j'.' '.$monthNames1[$now->format('n')].'Y')?></li> <li> <?php var_dump($nextDay); ?> </li> <li><a href="<?php echo $_SERVER["PHP_SELF"]. "?newdate=". $nextDay . '&dayview' ?>"><img id="nextday" src="Images/day_next.png"></a></li> </ul> There is also a function called datecalculation which as it's name implies makes the date calculationsand for the sake of brevity I am not showing(If the need arises I will). The aim here is to make the above work with ajax...I have failed so far.Here is the js: $('#nextday').click(function(){ event.preventDefault(); $.ajax({ type: "GET", url: "Calview.php", dataType:'dataString', data:{"newdate":26-06-2013}, cache:false, }); }); For testing purposes I 've set a date of 26-06-2013.It does not work though and in the Chrome Dev Tools, in the error console here is the link that is sent.Calview.php?newdate=-1993&_=1372187956455". It must be the date but I do not understand why it goes to the server with the above format. Link to comment Share on other sites More sharing options...
dsonesuk Posted June 25, 2013 Share Posted June 25, 2013 26 minus 06 minus 2013 equals, yes! you guessed it -1993 da dah. Link to comment Share on other sites More sharing options...
jimfog Posted June 25, 2013 Author Share Posted June 25, 2013 Ok...I made a slight change just to see what will happen.I just chose to send 27... $('#nextday').click(function(){ event.preventDefault(); $.ajax({ type: "GET", url: "Calview.php", dataType:'dataString', data:{"newdate":27}, cache:false, }); }); I got this Calview.php?newdate=27&_=1372195414504". plus that the problem remains that the calendar does not go in the next day after clicking the link. Link to comment Share on other sites More sharing options...
justsomeguy Posted June 25, 2013 Share Posted June 25, 2013 Well, you probably need to send it the correct date to go to. Do you understand dsonesuk's post, why the date value you're sending is -1993? Changing the date to 27 doesn't really show that you understand what's going on. Link to comment Share on other sites More sharing options...
jimfog Posted June 26, 2013 Author Share Posted June 26, 2013 Well, you probably need to send it the correct date to go to. Do you understand dsonesuk's post, why the date value you're sending is -1993? Changing the date to 27 doesn't really show that you understand what's going on.I did understand why I got 1993(it is the result of subtraction of the numbers I sent).How am I going to send the date? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 26, 2013 Share Posted June 26, 2013 It needs to be a string. Link to comment Share on other sites More sharing options...
jimfog Posted June 27, 2013 Author Share Posted June 27, 2013 It needs to be a string. Οκ...Ι fixed that...you will see the code in a while...but there is something else that I really cannot figure out,first the ajax code: $('#nextday').click(function(){ event.preventDefault(); $.ajax({ type: "GET", url: "testajaxcalendar.php", dataType:'text', data:{newdate:"29-06-2013"}, cache:false }); }); Here is what the console outputs in chrome dev tools whenever I click the above link and an ajax request is made: XHR finished loading: "http://localhost/Appointments/Administrator/testajaxcalendar.php?newdate=29-06-2013&_=1372359365989". This 1372359365989 seems to be a unix timestamp but I HAVE NO IDEA where it came from? Here is the html of the link: <a id="nextday" href="/Appointments/Administrator/Calview.php?newdate=28-06-2013&dayview"><img src="Images/day_next.png"></a> Above you see, 28-06-2013 as newdate....this is just printed from php...for sending through ajax and for testing I put 29-06-2013. But what bothers me is that unix timestamp which is sent with AJAX...what its origin might be? Link to comment Share on other sites More sharing options...
justsomeguy Posted June 27, 2013 Share Posted June 27, 2013 Setting the cache option to false causes it to add the timestamp, to make the URL unique. You can find that out in the jQuery ajax documentation. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now