0

I'm working on a script right now for a simple shout box. I was using $.get() before without any issues. I then switched over to $.post() so I can pass Cyrillic characters to php.

I switched over everything to post already in both the javascript and php files. Firebug shows that the variables are not empty and being sent and their is a standard response from the php script, but not the right one. I tried printing the whole $_POST variable scope, but just gives an empty array. What am I doing wrong?

$.post('file.php', { sc_com:'submit', name:userboxVal, color:swatch, msg:escape(msgboxVal) }, function(data) {
    if(data.error) {
        msgbox.focus();
        shoutError(data.error);
    } else if(data.status=='posted') {
        msgbox.val('').focus();
        refreshShouts(opts,'ajax');
    }
}, 'json');

PHP

$sc_com = strip_tags($_POST['sc_com']); // Empty
print_r($_POST); // returns Array()

Not sure why you would need the PHP code for it? The whole thing is over 500 lines, but that is the most important part...

Kyle Ross
  • 2,090
  • 4
  • 20
  • 27
  • 1
    Does the problem also occur when you send only non-Cyrillic characters ? And could you also post the data you see being sent in Firebug ? – Arc Sep 18 '10 at 22:32
  • Agree with Matthew: this doesn't tell us the whole story. If your PHP code is more than `print_r($_POST)` then the problem must lie within there, because the jQuery looks okay. – JAL Sep 18 '10 at 22:32
  • The PHP code is over 500 lines long consisting of a custom class. It doesn't matter if it was 1 line or 6,000 lines, the part I included in the main post is at the top of the script and the response from the file is Array(). Firebug says 200 OK and shows each of the variables with their values being sent. The response shows the variable as being empty... – Kyle Ross Sep 18 '10 at 22:54
  • 1
    Do you trace it in your firebug NET tab? What does it show? – Itay Moav -Malimovka Sep 18 '10 at 23:02
  • 1
    Pare it down to an even simpler example. Does it work if you do `$.post('file.php', { test: 'test value' })`? What about if you add in the `'json'` parameter; does that break it? What about adding the cyrillic characters? If even the first breaks, I would imagine it's a PHP problem related to server configuration---perhaps some kind of overzealous security setting. – Domenic Sep 19 '10 at 07:50
  • What does `var_dump($_POST)` show? – Bot Sep 20 '10 at 15:40

1 Answers1

1

Try serializing the data before sending it to php? jquery $.post empty array

Community
  • 1
  • 1
Bot
  • 11,868
  • 11
  • 75
  • 131