Posting null values via AJAX
Posted
by nickf
on Stack Overflow
See other posts from Stack Overflow
or by nickf
Published on 2010-06-15T04:35:53Z
Indexed on
2010/06/15
4:42 UTC
Read the original article
Hit count: 268
Using the jQuery $.post
function, if you send a null
value, it arrives at the server side as "null"
. Example:
Javascript:
$.post('test.php', { foo : null });
PHP:
var_dump($_POST['foo']); // string(4) "null"
I understand why this is so, but was wondering the best way to work around the limitation? Should you:
- Loop through all the variables in JS before you send them and replace with an empty string?
- Interpret
"null"
asnull
on the server side? - Don't send the variable at all?
- Something else?
© Stack Overflow or respective owner