jQuery 'If' statement string comparison not working

前端 未结 3 522
眼角桃花
眼角桃花 2021-01-04 09:35

I\'m having a very hard time trying to do something very simple. Here\'s the code:

        if(data == \'success\') {

            alert(\'foo\');

        }          


        
相关标签:
3条回答
  • 2021-01-04 09:40

    Client side validation working fine.

    $.trim() fine.
    

    Thank You Nick. It took me long to understand why its not working ...

    0 讨论(0)
  • 2021-01-04 09:57

    You can remove the trailing ?> in your file, if it is the last line in the file. I want to response to the comments to the original issue, but i don't see how.

    0 讨论(0)
  • 2021-01-04 10:01

    You can fix it on the client side using $.trim() like this:

    if($.trim(data) == 'success') {
    

    Or, a better approach would be removing the new-line coming from the server-side, probably an erroneous new-line in your PHP somewhere, check before or after the <? ?> block, this is most often where they crop up.

    Or, just exit after outputting your content, like this:

    if($update) {
      echo 'success';
      exit();
    }
    
    0 讨论(0)
提交回复
热议问题