2

I have several different ajax calls on the same php page, but I get undefined index for only one function (createAlbum).

I send exactly the same parameters in each of my ajax calls. It worked fine for a few tests, but now it only works for the other ones, but not for this specific call.

I suspected that the .js file was still in the browser cache, so I cleared it and tried with other browsers, which worked for a few more attempts.

Now, I can't get it working on any browser, and definitely don't understand why.

Here is my ajax call :

$.ajax({
    type: "POST",
    url: BASE_URL,
    data: {
        action: "createAlbum",
        data: JSONAlbum
    },
    cache: false,
    success: callback
});

My php file handling the request ($_POST['action'] is always undefined with the above request) :

if (isset($_POST['action'])) {
    switch ($_POST['action']) {
        // Handle the action
        // ...
    }
} else {
    echo 'ACTION : '.$_POST['action'];
}

The header containing the ajax parameters ("data" is a json containing one or more blob images, this might be the problem, but I didn't find anything saying so) :

header parameters

And finally, the response containing the error :

php response

I really hope this is not a dumb error of mine, but I asked a friend before posting, and he can't find the solution either.

Thanks for your help !

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
  • *There you go*... undefined. http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index and check your console. – Funk Forty Niner Nov 26 '15 at 21:50
  • Have you tried running the script without sending ``data`` - only ``action``? Does it still show the same Error? – Guido Kitzing Nov 26 '15 at 21:55
  • How many seconds do you wait before the output? then check your php.ini for `max_input_time` – Luca Rainone Nov 26 '15 at 21:58
  • Also, you may want to check ``post_max_size`` (PHP setting) size, just in case it is set to a lower value, than the size of your post. If that is the case, the ``$_POST`` superglobal will be emptied. – Guido Kitzing Nov 26 '15 at 22:01
  • @GuidoKitzing I tried work without Data so it may be caused by base64 images like chumkiu said ! – Joseph Gremaud Nov 26 '15 at 22:22

1 Answers1

1

You said that the error not happens all the time (in some call yes, in other no).

The body post is sent, you see it in console. So we can exclude javascript problem.

So the problem is something that happens before or during the process.

PHP has some limitations on input vars, you can see it in php.ini.

I see that you send images in base64, so it's probable that something of these limitations are triggered.

See for example:

Luca Rainone
  • 16,138
  • 2
  • 38
  • 52