duanmeng1858 2014-03-19 16:55
浏览 46
已采纳

if,else在jquery中用php数据声明

So I have a javascript ajax call like so:

      $.ajax({
        type: "POST",
        url: "/checkout/doCharge",
        data: dataString,
        success: function(data) {
          if(data == '1'){
            $("#CheckoutSubmit").prop('disabled', false);
          }
          else{
            $.growl.error({ message: "Your card was declined! Please try again." });
          }
        }
      });
      return false;

And the php call is:

$response = $this->stripe->charge_card($amount, $card, $desc);

    if($response['paid'] == 'true'){

        echo '1';
    }
    else{
        echo '0';
    }

Right now, the if(data == '1') is not working. it doesn't throw any error either. I am trying to get data as 1 if the paid response is true and 0 if the response is false.

  • 写回答

1条回答 默认 最新

  • doucong7963 2014-03-19 17:07
    关注

    Use $.trim to remove extraneous whitespace around the response.

        success: function(data) {
          data = $.trim(data);
          if(data == '1'){
            $("#CheckoutSubmit").prop('disabled', false);
          }
          else{
            $.growl.error({ message: "Your card was declined! Please try again." });
          }
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器