Richard
Richard

Reputation: 4546

passing null values from ajax to phpscript

I am having some problems with null values

Is there a good way of passing the null values from js in a way that they are interpreted the same.

This apparently is not the same

ajaxNullVar = null;
post_var = {'action': 'update_foto','fotoid': fotoid, 'ajaxNullVar': ajaxNullVar };
        $.ajax({
            url: post_url,
            data: post_var, 

in php

if ($_POST['ajaxNullVar']!=NULL)$ajaxNullVar='php null is not the same as a js null';
alert($ajaxNullVar);

I tested for a while now, and setting the null values in php, does not cause a problem when posting to the api, but coming from ajax it does?? Before I start thinking about a workaround, I thought I ask here first.

thanks, Richard

Upvotes: 1

Views: 1111

Answers (1)

Josh
Josh

Reputation: 6322

if you don't pass that parameter then i think php will read it as null. i've done the following basic test:

<?php
if($_GET['a'] == null){
   echo('null');
} else{
   echo('not null');
}
?>

Upvotes: 1

Related Questions