Jump to content

AJAX being weird

Go to solution Solved by mikat,
41 minutes ago, myselfolli said:

... I fixed it. Don't ask me how, I don't have the slightes clue. But it works now ^^

If the post is solved, mark is as solved :)

 

 

 

 

Okay, I really have no idea what's going on, but here's my problem:

 

I built a calendar for a website I am working on. To load the appointments for each month, I'm making jQuery AJAX calls to a php document, which in turn loads the stuff from a database. And here's where it gest funny:

On 11/12 months, this works flawlessly, but on month 12 (which incidentally also is december in this case) the AJAX request just fails. I've already checked the SQL statement, it works with the data I'm supplying, I really have no idea what to do.

 

Relevant (?) code:

 

The JS code:

$.ajax({
    type: "POST",
    url: url,
    data: {
	//sending a post-request to my php document, with the year and month to fetch the coresponding appointments
      "year": year,
      "month": month,
    },
    success: function(data){
      //I obviously never get this far
      $.each(data, function(i, item) {
        //do stuff with the data
      });
    },
  	error: function(data){
      console.log(data);
    }
 });

The PHP code:

<?php
header('Content-Type: application/json');

  //establish connection (not gonna show you this part, because security)

  $year = htmlspecialchars($_POST["year"]);
  $month = htmlspecialchars($_POST["month"]);

  $sql = "SELECT * FROM `termine` WHERE `year` = '$year' AND `month` = '$month'";
  $appts = $pdo->query($sql)->fetchall();

  echo json_encode($appts);

?>

Where would I look for clues? The error message I get looks cryptic (would post, but it's long af).

 

Any ideas?

75% of what I say is sarcastic

 

So is the rest probably

Link to comment
https://linustechtips.com/topic/856935-ajax-being-weird/
Share on other sites

Link to post
Share on other sites

sounds like something is counting from zero and you or another part of the program is counting from one :)

can you try:

data: {
  //sending a post-request to my php document, with the year and month to fetch the coresponding appointments
  "year": year,
  "month": month-1,
},

 

Link to comment
https://linustechtips.com/topic/856935-ajax-being-weird/#findComment-10669423
Share on other sites

Link to post
Share on other sites

1 hour ago, mikat said:

sounds like something is counting from zero and you or another part of the program is counting from one :)

can you try:


data: {
  //sending a post-request to my php document, with the year and month to fetch the coresponding appointments
  "year": year,
  "month": month-1,
},

 

Sorry for the late response!

 

I tried your suggestion, no difference. It would've suprised me if that was the problem, since the data being sent by jQuery is not used for anything but grabbing the corresponding database entries...

 

Any other suggestions?

75% of what I say is sarcastic

 

So is the rest probably

Link to comment
https://linustechtips.com/topic/856935-ajax-being-weird/#findComment-10669805
Share on other sites

Link to post
Share on other sites

Just now, myselfolli said:

Sorry for the late response!

 

I tried your suggestion, no difference. It would've suprised me if that was the problem, since the data being sent by jQuery is not used for anything but grabbing the corresponding database entries...

 

Any other suggestions?

how are you getting the dates? can you make sure that you're using the same system in your database and in your website? 

Link to comment
https://linustechtips.com/topic/856935-ajax-being-weird/#findComment-10669816
Share on other sites

Link to post
Share on other sites

Just now, mikat said:

how are you getting the dates? can you make sure that you're using the same system in your database and in your website? 

That was actually one of the first things I tried, no problem there. And it's working for the other 11 months...

75% of what I say is sarcastic

 

So is the rest probably

Link to comment
https://linustechtips.com/topic/856935-ajax-being-weird/#findComment-10669820
Share on other sites

Link to post
Share on other sites

1 minute ago, myselfolli said:

That was actually one of the first things I tried, no problem there. And it's working for the other 11 months...

can you make sure that there are DB entries with the month december?

also: what does the ajax error say?

Link to comment
https://linustechtips.com/topic/856935-ajax-being-weird/#findComment-10669824
Share on other sites

Link to post
Share on other sites

1 minute ago, mikat said:

can you make sure that there are DB entries with the month december?

 

Can and did, yes.

 

1 minute ago, mikat said:

also: what does the ajax error say?

The error is really a mouthfull, it's JSON by the looks of it

75% of what I say is sarcastic

 

So is the rest probably

Link to comment
https://linustechtips.com/topic/856935-ajax-being-weird/#findComment-10669848
Share on other sites

Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×