douhe4336 2010-01-27 22:28
浏览 39
已采纳

将空值从ajax传递给php脚本

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

  • 写回答

1条回答 默认 最新

  • douti0687 2010-01-27 22:36
    关注

    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');
    }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向